Self-harm is done for one or both of two reasons:
Punishment; self-harmers think they deserve it,
or
To regain a sense of control; self-harmers feel powerless and lost, and hurting themselves is something they can control, and the familiar pain and healing process comforts them. The sensation of the dopamine hit when the body begins healing itself distracts from immediate problems, and it is often the only form of relaxing or stress-relieving the self-harmer is aware of.