What is the origin of negative thoughts and whisperings and how do we deal with them?
Answered by Sayyidi Habib Umar bin Hafiz (may Allah protect him and benefit us by him)
They may be either be a type of punishment for disobedience or a test from Allah. Either way, they do not harm the person as long as they dislike and ignore them. Of course, if someone has fallen into disobedience, they must make tawbah. These thoughts may also be the work of the Devil, who out of envy attempts to shake that person’s faith and tranquillity of heart. Allah says: Secret conversation is the work of Satan, designed to cause trouble to the believers, though it cannot harm them in the least unless God permits it. Let the believers put their trust in God (58:10). There is a great reward in remaining steadfast and not allowing yourself to be affected by these thoughts, and if someone is truthful, Allah will remove them.
See also:
https://muwasala.org/2013/04/27/on-removing-bad-thoughts/