https://islamqa.info/en/answers/224718/treating-waswasah-by-seeking-refuge-with-allah-from-the-shaytan-and-ignoring-it. This website has this situation and aligns with some of the discussions of psychology.
I am not a psychologist at all (do not take this as an medical expert's advice), but this seems like one of the symptoms of ocd. There are obsessions (bad thoughts), and compulsions (compulsions are where one tries to repeat behavior to stop the thoughts). You have obsessions, which are "uncontrollable, recurring thoughts". I am not sure if you indicated this in the question, but it is possible that you interact with the thought by denying it, which is an attempt to "repeat behavior to stop the thoughts", or in other worse a compulsion.
How to ignore the thoughts: The more you pay attention to these thoughts, the worse they will become. If the thoughts come just start doing something else. You may keep telling yourself to ignore the thoughts, but this will cause the thoughts to strengthen. For example, you might think the thought "this person is a bad person". You may tell yourself "ignore this thought" and keep repeating this action. By interacting with the bad thought, you are strengthening the thought so that you will think "this person is a bad person" more often. Let the thought pass and do not try to fight it with denial. Simply focus on another task if the thought comes.