It is not sinful when bad thoughts come to your mind, no matter how bad they are. If you stop yourself from acting on those thoughts, you will be rewarded. For example, if you thought of committing murder, but weren’t actually going to do it, you are not sinful.
What the Qur’an and Sunnah Say
The Prophet Muhammad said, “Whoever makes up his mind to carry out an evil deed, but doesn’t do it, Allah rewards him with one complete good deed. If he makes up his mind and then carries it out, he earns one sin.” (Bukhari #6491)
Try to figure out where this thought came from and cut off the source. For example, if the idea of murder came from a friend or a book, avoid that bad influence so it doesn’t reoccur.
Shaykh Mustafa Umar