To quote Jimmy Akin Senior Apologist at Catholic Answers:
"One of the characteristics of OCD is that it generates obsessions, which are recurrent thoughts that one cannot get rid of, that one finds painful, and that are “ego-dystonic.” That is, you feel like they just force their way into your mind unbidden, even though you don’t want them there.
Obsessive Compulsive Disorder is an anxiety disorder where part of your mind tries to throw painful thoughts at you in order to increase your stress level. The reason you get recurrent thoughts about sin rather than thoughts about happy things is that these thoughts pain you. That’s what the condition tries to do: Give you painful thoughts.
It is obvious from what you write that you do not want these thoughts, that you hate having them and want desperately to be rid of them.
That’s good!
It shows that these thoughts are ego-dystonic and thus (THIS IS THE IMPORTANT PART) they are NOT SINFUL.
Merely having a thought occur to you is not a sin, no matter how bad the thought it. At most, having the thought occur to you is just temptation. It only becomes sin if you endorse it with your will. But the fact that you clearly do not want these thoughts and that you oppose them means that you are not consenting with your will (CERTAINLY not in the fully human way needed to commit a mortal sin)."
And he said:
“When you are in confession, DO NOT attempt to laboriously explain all of the thoughts that you are having. Attempting to do this will reinforce and re-awaken the thoughts. This gives you an excusing cause from making a materially integral confession in regard to the thoughts–which you really don’t need to do anyway since they aren’t sinful since you don’t approve of them, but I know you’ll feel the need to confess them (if you’re Catholic). Here’s how to do that. Say this: “I have obsessive compulsive disorder, which causes me to have thoughts of a sinful nature that I do not want and do not approve of. I wish to confess any slight degree of cooperation of the will I may have given to these thoughts.” And LEAVE IT AT THAT.”
He has also not recommended confessing them as well:
“However, be assured that the thoughts OCD generates are not sins. We do not have much control over the thoughts that occur to us, and people who have OCD have a quirk in their brain chemistry that makes them more susceptible to such thoughts than others. As you point out, these are not things that you would actually do. They are therefore what psychologists term ego dystonic thoughts, contrary to one’s beliefs and values. As a result, there is not the kind of cooperation of the will needed to make them sinful. In fact, you should not confess these thoughts in the confessional, as focusing on them will tend to reinforce them and exacerbate the condition. You should simply do your best to ignore them. The more you can relax and ignore them, the better you will get.”
(We here are not permitted to give advice about medical conditions - and such should come from a medical doctor etc - but what is offered above is from Catholic Answers Senior Apologist and is for the theological- spiritual purpose of the question asked).