Yeah, being unable to stop thinking of taboo words (or in very religious people, thoughts that are blasphemous to the person's religion) is a possible manifestation of OCD. In the religious context, it's called scrupulosity.