Masha, relax. If you cannot just relax, then repeat the following mantra: the world is a dream of emptiness, in it you and me, you and me, we live and die in a dream, we live and die in a dream. This is theomantra, the main mantra of theomism, it helps to relax and calm down. Just repeat it - and you will feel calmer, easier.
When I experience a burning urge to self-destruction, accompanied by an irresistible desire to create a secret underground boxing club, I always repeat theomantra - and it lets me go. Everything suits me in life: I love my job, my boss, my country, these are all copies, copies, copies. We are the unexpected children of the Lord. He hates us.
This is a variant of auto-aggression. This is a rather serious symptom that your nervous system is not able to cope with some kind of stress. You definitely need to consult a specialist (psychologist / neurologist / psychotherapist). Please don't leave it like this.
So offhand through the Internet, very few people will tell you anything (more precisely, but hardly in the case).
The most "popular" option in such cases is not masochism that comes to mind, although how to look ... Most likely, such a "habit" has developed as a distracting strategy, when it is necessary to avoid some unpleasant emotional or other internal experiences through the experience of physical bodily pain.
And, in fact, as long as there is a need for this avoidance, and this function is performed by self-torture - it does not go anywhere especially, as far as experience allows one to judge. What's the funniest thing is trying to wean someone from this, using punishment (you are already punishing yourself, somewhere else) :)