My 6 year old son hits himself and punches himself in the face when he hurts himself(like accidentally smacking his hand hard on my bedpost), or if he is frustrated and angry. He has shown other symptoms of ADHD and autism, so we brought him to a behavioral specialist. He is undergoing evaluations. Hitting oneself is autism related. Behaviors of ADHD, Autism Spectrum Disorder and sensory processing issues do overlap, making exact diagnoses difficult. I am relieved, however, that the doctor said that hitting isn't necessarily indicative of self harm tendencies pr mental illness.
So much research on ADHD, ASD, and SPD is happening as we speak; I am always learning something new. All I can do with my son is practice appropriate and safe ways to express frustration and anger. I stopped telling him that hitting himself is "bad" bcs he takes that as "I am bad". And that's bad! So we just keep learning. And it is good.