I'm someone who pretty much never swears, but there have been times, when I have done just as you describe. It's almost like a stim, the repetition or use of words you wouldn't usually say also gives them more power, which serves as a kind of release. Maybe subconsciously, you've got some pent up emotions needing to be released, maybe not. But, I did find the following as well ...
Improved psychological and physical health — The health benefits of swearing include increased circulation, elevated endorphins, and an overall sense of calm, control, and well-being. The key is to do it sparingly and not to get angry at the same time, which would be very bad for you — as well as terribly vulgar.
https://www.psychologytoday.com/us/blog/hide-and-seek/201205/hell-yes-the-7-best-reasons-swearing
Professor Timothy Jay of Massachusetts College of Liberal Arts in the States, whom I have since had the pleasure of meeting, has forged a career investigating why people swear and has written several books on the topic. His main thesis is that swearing is not, as is often argued, a sign of low intelligence and inarticulateness, but rather that swearing is emotional language. In his words: ‘Curse words do things to sentences that noncurse words cannot do’ (Jay, 1999, p.137). Indeed, Professor Jay is rather scathing at psycholinguists’ tendency to have largely ignored swearing. He says: ‘Linguistic definitions of language [that omit cursing] are ultimately invalid, although polite’ (Jay, 1999, p.11).
...So, our research shows that swearing can help people better tolerate pain, that too much swearing in everyday situations can reduce its effectiveness, and that swearing probably works by making people feel more aggressive, in turn setting off the fight or flight response. Swearing as a response to pain appears not to be an expression of pain catastrophising, because if it were, there should have been a heightened sensation of pain with swearing. The idea of swearing in response to pain as disinhibitory behaviour also seems unlikely as this predicts no alteration in pain perception, contrary to our findings. Our research instead indicates that swearing as a response to pain represents a form of pain management. While this had never been empirically demonstrated before, it seems nevertheless to have been well known anecdotally by nurses, midwives and mothers-to-be.
The media reaction to our research was unbelievable. When the first paper was published in late July 2009 my phone rang off its hook as journalists from all over the world sought to arrange interviews: with Evan Davis on The Today Programme, with Arthur Smith for The One Show and with Stephen Fry and Brian Blessed for Stephen Fry’s Planet Word.
Actually, on reflection, we were probably quite lucky in the timing of our research on swearing and pain. Maybe a few years earlier and it would still have been too much of a taboo topic to secure peer review publication. This is not so today. Indeed, it really does appear that ‘now’ is the time for researching the psychology of swearing, as demonstrated by the recent publication of a number of fascinating studies.
https://thepsychologist.bps.org.uk/volume-26/edition-9/swearing-language-life-and-death