Scrupulosity: is it devotion or a compulsion?
Two people can say the same prayer. For one it is devotion, for the other a ritual performed until it comes out clean. The difference is function, not faith, and most clergy will tell you the same.

The prayer gets started again, because that one did not count. And again, because you were not concentrating. You confess the same thing for the fourth time, phrased slightly differently, in case the earlier phrasing was a technicality. You check whether you meant it. You check whether you still believe. Then you check whether the checking is itself a sin.
From the outside this can look like piety. From the inside it is torment. And the question that keeps people from getting help is the one I want to answer here: how do I know whether this is my faith or something wrong with me?
The distinction is not sacred versus secular
I am not going to adjudicate your theology, and I do not need to share your beliefs to treat this. The distinction we work with is between two things that can look identical and function completely differently.
Two people can say the same prayer, word for word. For one, it is devotion: chosen, offered, finished, and it leaves them somewhere. For the other, it is a ritual performed to make a feeling go away, repeated until it comes out clean, never quite finished, and leaving them exactly where they started.
Devotion is chosen, and it can be completed. A compulsion is compelled, and it cannot be completed, because the feeling it is trying to remove returns and the ritual has to be done again, which puts you back at the starting line with the doubt intact.
What clergy tend to say
Scrupulosity is one of the oldest described forms of OCD. Clergy have recognised it for centuries, and most will tell you, often more bluntly than I would, that it is not piety and it is not good for your faith either. A conscience that cannot be satisfied is malfunctioning, and every tradition I have worked with distinguishes between an intrusive thought and an intention, between a scruple and a sin.
Where it helps and you want it, I will work alongside your priest, minister, rabbi or imam. A clear message from someone inside your tradition that you are not required to keep answering this can be worth several sessions, and where the line between your genuine religious obligations and what the OCD has added on top is genuinely not mine to draw, we get it drawn by someone qualified rather than guessing at it in the room.
Why the thought arrives where it does
A blasphemous thought in the middle of a prayer. An obscene image during a service. A doubt about whether you believe any of it, arriving exactly when belief matters most. OCD goes after whatever you hold most carefully. The thought lands precisely where it will do most damage because that is where the alarm is most sensitive. The religion did not cause this; people with no faith at all get the moral version, endlessly auditing whether they are a good person. A tradition that takes conscience seriously simply gives OCD a great deal to work with.
The compulsions
Once the thought has landed, the compulsions follow. Repeating the prayer. Re-confessing. Mentally reviewing whether you meant it. Checking whether you believe. Searching for a ruling that settles it, finding three, and now having a new question. Avoiding the service, the reading, the word. Each buys a few minutes and teaches your brain that the case is still open.
What treatment does
The treatment is CBT with exposure and response prevention, and it does not require you to loosen your faith. We map the cycle, then take the compulsions out gradually, by agreement: the repeating, the re-confessing, the reviewing, the checking, the avoidance. What you get back is the ability to pray, or sit in the service, or simply be a decent person, without a running audit, which is what you were trying to do in the first place.
People generally finish this treatment more settled in their tradition, not less. If you cannot tell whether the prayer is worship or ritual, there is more on how I treat religious and moral OCD.