I see a number of "Why is my child doing x to hurt him/herself"
I hope that this may shed a little bit of light. When I do such behaviors it is because I feel stressed way beyond my threshold. Every human being has a melting point when they just throw up their arms and "Can't take it anymore!" I've seen it portrayed in NT culture as slapping one's head, etc.
Anyways what I am feeling right before and in the midst: Extreme anxiety I can't describe or put into words. I lose all logical thought and react on an instinctive level. It is the fight or flee reaction. I can do one of two things. Either I lash out in aggression or I flee like a wild animal set free from a cage.
Since it is not socially acceptable to attack people, I turn that anger against myself.
If it is an argument that set it up or a reaction to mounting anxiety between my parent and me, usually such a dramatic reaction will get them to stop yelling at me and work on a way to calm down. If you notice you're getting stressed out and starting to raise your voice, maybe that is a clue that both of you need to find a way to calm down.
I find when I am upset, having alone time to just back off and get distracted by some other activity helps a LOT. If I have to, I like to talk it out with someone who does not get emotional.
I wrote an essay about a specific example of one that happened to me as a 24 year old: