That's in my humble experience of not enormous experience--seriously take it with a grain of salt. But usually, when I've had friends who were hurting themselves, it was because they had someone else telling them they were rotten and guilty and etc. etc.--or that they felt was telling them that. They want desperately to please this person, but they can't; and often, that person has some sort of power over them, to the point where there's no way they can fight without incurring severe damages to themself; so they yield, and part of yielding means taking the abuser's side.
And that means hurting yourself, because you're doing what the abuser wants--so that they won't hurt you more, since they can hurt you worse. Recognizing that you're being abused can be a far worse experience than chronically hurting yourself, especially if the abuser is someone you're depending on and can't leave for a number of years. Sometimes the abuser only remains in your head--not someone you're still in contact with, but their messages are still there, ready to tell you at any moment that that little mistake you made means you're worthless. Sometimes it can be set off by a single act of profound violence. Sometimes it's multiple, overlapping experiences of abuse which on their own could be dealt with, but together form a nasty brew.
Abuse can mean years of trying to put yourself back together, hold it together, and so on. Sometimes if you hurt yourself you can save enough mental cycles to make progress, (or go in to work instead of just staring at the wall) so that next time you want to do that you have a little bit more energy to resist. It gives you something to focus on, so that rather than having to talk yourself through the exhausting and exhaustive "Why I Don't Need To Be Punished Today" dialogue, you can just feel that residual pain and--there, you don't have to be punished because it's already happened. Or taking your own side means curling into a ball and screaming and crying in pain for the sheer indignity and injustice of what's been done to you; and maybe you think that would be socially unacceptable, or you don't have the energy just then to deal with how tired you'd be after (even if you'd feel a lot better), or someone made fun of you for crying before, so that you'd have to somehow deal with that too, or you're scared that people will come to "help" you and you'll just end up abused again now that you're even weaker and easier to pick off. Or maybe you still just couldn't stand feeling that degree of pain.
Or you want to kill yourself to get out, so you do something approaching that so you can keep going just a little longer.
When this sort of complex is set up, hurting yourself can feel good and be relaxing--a relief. It can be a temporary surrender to the things overwhelming you, so that you can get up and fight the good fight just one more day. Because that's usually the scale the war is fought on, though sometimes it can also be even by the minute.
Anyway, those are some possibilities, but they certainly aren't exhaustive.