From whatever information you provided, it seems that you are having obsessive thoughts.
You need to provide more information as since how long you are getting these thoughts, how frequent they are occurring to you, to what extent you have control over these thoughts.
It can be due to many reasons.
If these are troubling you a lot, consult a psychiatrist for further evaluation and treatment
Next Steps
Consult a psychiatrist