This sounds like an intrusive thought, which is a symptom of Obsssive Compulsive Disorder. One of the best ways to conquer an intrusive thought is to ignore it and not give it any judgement. When you judge an intrusive thought, you give it weight. This can cause a wave of anxiety where you judge yourself harshly for having the intrusive thought to begin with and creates the conditions for further intrusive thoughts.