That can happen with several mental health conditions - including OCD, an anxiety based disorder. There can be strong links to PTSD. I used to have thoughts like that when I had OCD. I was so scared I would act on them, which is apparently part of the disorder. I'm not sure what is going on for you, but just wanted to tell you that you are not alone in this.