It could be a symptom of OCD, repetitive thoughts coming to head against your will is known as obsessions. You know they are irrational but you just can't avoid them. It is a psychiatric problem associated with intense anxiety and distress. You must consult with a psychiatrist. With suitable medications and treatment it can be completely cured.
Next Steps
For more specific answer and advice regarding the management, you can also post a direct query here on practo.
Health Tips
It is treatable.