I would completely ignore it! When he starts doing this, just walk away and give him no attention whatsoever. Don't even react emotionally. I know you are concerned he will hurt himself, but believe me, when he is not getting the attention he will stop. Do not even mention it or negotiate with him or explain anything. When he stops, give him lots of good attention and praise him for behaving in general terms (without mentioning the head banging). He will get the picture!
The same technique works for temper tantrums. My son used to throw himself to the floor and kick and scream. Then he learned that it hurt less to do that on the carpet, so he would move into the family room and do it there! I read this in some parenting book to just ignore it; actually step over him and walk away. When he had no audience, the behavior stopped. Works like a dream!
It is harder to do this in public....in that case you might need to remove him from the setting quickly and calmly and just wait outside till he is done. Kids do these things because it gives them a sense of power and control to see the adults get so worried and upset. Think about it.....when you are 2, there is very little you actually have control over! He is testing his limits and this is just a normal part of growing up. As they say "this too shall pass!" They don't call it terrible two's for nothing. He might move on to something else, like not eating or holding his breath or potty training struggles...again it's all part of asserting his newfound powers, and is normal and healthy. Your role is to remain consistent and in control of your emotions. It actually comforts kids to be cared for by a well-controlled adult...it gives them a sense of security. When you are not with him, find a sympathetic adult to share your frustrations with. We've all been there!!
Peace to you and your family over the holidays....
K. G.