lalochezia
According to Wiktionary, lalochezia is “The use of vulgar or foul language to relieve stress or pain.”
Other definitions that I’m seeing online focus on the idea of getting emotional relief from swearing, but I think in the context where I first encountered the word, it was related to experiments that suggest that swearing can make physical pain more bearable.