Know that having bad thoughts about someone is forbidden just like having bad speech about him. So just as it is forbidden for you to speak to others about the defects of a person, it is likewise forbidden for you to speak to yourself about that and to hold bad thoughts for him.
“O you who believe, avoid much (types) of suspicion. Verily some (forms) of suspicion is a sin.” [Surah Al-Hujuraat: 12]
And Abu Hurairah (radhi Allaahu anhu) reported that Allaah’s Messenger (sall Allaahu alayhi wa sallam) said:
“Beware of suspicion, for indeed suspicion is the most untruthful form of speech.”
The ahaadeeth with this same understanding I have mentioned here are many. What the backbiting of the heart means, is: When the heart has firm conviction and holds bad thoughts about someone. But as for the notions that occasionally display in one’s mind or when one talks to himself, then as long as these thoughts do not remain established and continuous in him, it is excused according to the consensus of the scholars. This is since he has no choice in the matter as to stop it from occurring nor can he find any way to liberate himself from it when it does occur. This is the understanding of what has been authentically established (in the texts).
The Messenger of Allaah (sall Allaahu alayhi wa sallam) said: “Indeed, Allaah has permitted for my ummah that which their souls whisper to them, so long as they do not speak it out (audibly) or act upon it.”
The scholars say: “This refers to the notions that form in one’s mind, but do not become settled or established there.”
And they said: “This is regardless if the notion consists of backbiting, disbelief or so on (i.e. it is pardoned, so long as it does not settle). So (for example) whoever’s mind becomes flooded with thoughts of disbelief, but they are only thoughts, without him intending to have them carried out, and he then rids himself of these thoughts right after they occur, he is not a disbeliever nor is there any sin on him…
The Backbiting Of The Heart – Imaam An-Nawawee