The Messenger of Allah ﷺ said, "Allah has pardoned for my community the whisperings and thoughts that arise in their hearts, so long as they do not act upon them or speak them."
أخبرنا عبيد الله بن سعيد قال حدثنا ابن إدريس عن مسعر عن قتادة عن زرارة بن أوفى
قال رسول الله ﷺ إن الله عز وجل تجاوز لأمتي ما وسوست به وحدثت به أنفسها ما لم تعمل أو تتكلم به
Bukhari narrated it, Emancipation, chapter on mistake and forgetfulness in manumission, divorce, and the like, etc., no. 2528, and Muslim, Faith, chapter on Allah overlooking passing thoughts and impulses of the heart when they do not settle, no. 202/127, from the hadith of Misar bin Kidam with this chain, and it is also in Kubra, no. 5627. Yunus bin Ubayd also narrated it from Zurara with this chain (Abu Yaala, no. 6390).