This is an explanation provided by Saint Alphonsus Liguori, Doctor of the Church (and probably Patron Saint of the scrupulous, as he was one himself before becoming the best moral theologian in the Church):
> One should not omit to use that rule which has been wisely handed down by doctors, namely those who are of a God-fearing conscience, unless they morally know for certain that they consented to a grave sin, must be judged to be free from sin; for, as Fr. Alvarez says, it is impossible for sin to enter a soul that abhors it, since the soul will clearly recognize it for what it is. This is why it is often expedient to expressly impose upon the scrupulous to abstain from confessing thoughts of this sort unless they are so certain that they consented to them that they could swear to the fact. (St. Alphonsus Liguori [Doctor of the Church], Theologia Moralis Vol I. Q. 15)
Basically: If there's doubt, then there is no doubt (ie. if you are scrupulous and you are not sure whether you sinned gravely by doing X, then it means that there's no doubt that it wasn't a sin).
If there's a specific topic bothering your mind I might be able to help. I used to be scrupulous myself and diving deep into Alphonsus Liguori helped me be free of that. More importantly, if you have the time and leisure, you should totally read the first Volumes of his Theologia Moralis, this work is part of what got him named doctor of the Church, and the Vatican later too confirmed that one would not be in error by following any of the moral judgements made by St. Alphonsus in this work. Not everything in it is terribly interesting (you can skip or quickly skim over those sections, or simply download the Amazon Alexa app on your phone and have it read it aloud while you're driving) but Book 1 contains a very detailed and useful explanation of what one should do in cases of doubt (ie. whether something is a sin or not, grave or not), and Books 2-3 contain important sections on distinguishing between mortal and venial sin, fraternal correction, cooperation with evil, etc. A [much] friendlier and short summary of St. Alphonsus Liguori and his system can be found in Rey-Mermet's Moral Choices, but it has a very unfortunate first chapter with an very problematic "history of the sacrament of confession" that is most innacurate and barely short of heretical.