Thinking back on it from when I used to do it all the time, I think I would describe it less as a form of self-flagellation, and more as something one does when he's upset or frustrated and wants to hit something, but does not want to cause any destruction or hurt anyone. Smashing pots or punching walls can have far worse immediate consequences than taking it out on your own body. Of course, too much of the latter is a very bad idea. I'm pleased to report that my brain is still fully functional.