I’ve got OCD and I struggle with some pretty unholy thoughts as well. Honestly it used to happen in church a lot and I’d leave feeling disgusted and worse off than I was before I showed up. I know that the church typically views the problems that we have simply as scrupulosity since a lot of folks with OCD (myself included, maybe you) struggle with guilt, but it’s a legitimate and sever neurological problem that unfortunately doesn’t fit neatly into the box of scrupulosity.
I think the thing to remember is that it’s not your fault that you’re thinking these things. Most other folks can have a passing bad thought and hardly notice it, but for us it doesn’t go away. It gets stuck and we think it again and again and again, against our will. It’s an intrusive thought, though. It’s not something that you’ve invited into your own head space. Acting on the thought or doing something sinful because of it would be a sin, but simply having the thought is not your fault.
That being said, it’s still helpful to pray about it. When I get a bad thought in my head that I know isn’t in line with my own values or who I am, I pray the Rosary if I can. If I can’t, I say a silent prayer in my head. Still, counseling is always going to be very important and something that you should seek out. I’m not talking about religious counseling, even though it’s important to talk to your priest and let them know what you’re struggling with, but with a licensed medical professional. Exposure and Response Prevention, therapy and medication are always going to be your most effective weapons against this problem.
tl;dr - Your prefrontal cortex is physically and irreparably damaged and that’s forcing you to have these thoughts, so please don’t feel bad or personally responsible for them, but don’t hesitate to seek help through prayer and medical professionals either. It can and will help you. Good luck friend.