It can be viewed as a form of masochism, a sublimated form of sadism, or a means to experiencing algolagnia, a sexual tendency which is defined by deriving sexual pleasure and stimulation from physical pain.
It can be seen as a form of masochism, an unconsciously redirected sadistic behavior, or a method to achieve algolagnia, a sexual inclination characterized by deriving pleasure and excitement from physical pain.