Dont worry too much it is completely normal, although aweful to watch especially when they get hurt. My son went through this and also still does it on occasion when he is really frustrated. It is just an attention seeking thing i think, and my son usually did it when he couldnt get his own way.
I usually tried to ignore it and just walk away, he will soon learn that it hurts him, and if hes not getting attention from it he should grow out of it soon. Hope this helps. Good luck!