The main priority of living beings is to survive.
Pain is not bad: it is unpleasant. Like a red light on the semaphore, you don't like it, but the light is imperative. Pain is the main physiological signaling mechanism that warns us that our probabilities of survival are decreasing, as Newtonian Newton states. The mechanism is not bad. It is imperative.
But our survival is not controlled only by such mechanism. In fact, we have stronger mechanisms that determine our persistence in time. Consciousness, for example. And consciousness could decide to stop living. That's what suicidal people do. And what people who self-inflict pain intentionally.
Now, why do some people seem to enjoy pain? We have the stoics, people who enjoys tattooing for the mystical experience, writers who tell how do they decide to suffer, or even the MTV Jackass stars.
A paradox of survival is that the more an individual suffers, the better he becomes. The simple reason is that the body and the mind learn how to become stronger, so to be immune or at least resistent to a new attack like the one that caused suffering.
We have several examples of this.
- Nietsche stated that what doesn't kill you make you stronger, and that is literally true. If you break an bone, the bone becomes stronger after cured. If you practice rugby, you become iron.
- Physiologically, this is similar. For example, it's good to eat vegetables, because among other positive facts, they are aggressive against our body. They have toxins (that's the reason children don't like them, because a children can get intoxicated with them). They don't break, so the intestinal surfaces get stronger.
- People with important deseases, dead relatives, victims of human rights violations, etc. learn how to deal with such problems and usually become leaders helping others to improve life while suffering, and get back their lifes.
- A personal example. I've got kidnapped. Had to do psychotherapy for a couple of years (luckily, my therapist was also a philosopher, and a really good one). But I'm completely sure I've never got where I'm now without such traumatic experience. It might sound weird, but I'm really grateful of such experience.
So, some individuals could consciously self-inflict pain, in order to improve as persons, or physically. An ascetic life, like buddhists or franciscans is not far from it.