Head banging is something I have great familiarity with... unfortunately.
I grew up "bumping" my head at night to go to sleep. In fact, I used to have a picture of myself that was taken when I was around 2 years old I'd estimate. In the picture I had a round bald spot in the middle of my hairline where the hair had been worn away from bumping my head.
(I've also been a hair puller.)
I want to warn you, repeated head banging is a dangerous practice. I developed Meniere's Disease (a condition of the inner ear) & tinnitus as a result of my life-long head banging. I've also been treated for a detached retina. I can't say for sure that this was related to my head banging. But I believe it was.
I don't know of any particular coping skill for head banging... or hair pulling either for that matter. When I finally stopped battering my head was when I developed tinnitus as a result of it. Unfortunately, at that point, it was too late to do anything about it.
One thing I do, that perhaps helps a bit is that I massage my scalp. I do it because I'm an older man now & I'm trying to keep my scalp loose so it doesn't turn into a slab of concrete & cause what little bit of hair I have left on top of my head to fall out.
However I do think that the practice of massaging my scalp also helps give me something to do besides pull hair or other similar sorts of things.