In Natalie Angier's "Almost Before We Spoke, We Swore", Angier tells about 3 reasons for why people swear which stand out to me. The first point is that when you hear swear words they tend to stick in your head for a while. The second claim is that people tend to use swear words as anger management. Finally, the last point which I noticed is people with Tourette's or coprolalia.
Swear words sticking in your head has been tested through a game where you say the color of the word instead of the word itself. Though the participants tended to take longer to tell the color the first time vulgarities appeared, they found it easier to remember future times.
Swear words can also be used as a way of reducing stress and as a form of anger management.