A person is not held responsible in Shariat for thoughts that affect a person. This is the same fear experienced by the Sahaaba Radiallahu Anhum, that is if a person is held accountable for the thoughts experienced then how will one attain salvation from the punishment of Allah Ta’aala. It is on this occasion that Allah Ta’aala revealed the verses,
Allah will not burden a soul except according to its capability
Based on this the Ulema have mentioned that involuntary thoughts and whispers of the Shayateen experienced by a person are forgiven as long as one does not act upon them.
A person is only accountable for those actions that are carried out intentionally and voluntarily. The internal actions of a person are of two types:
– The first category is of those actions that are carried out intentionally such as Kufr and Shirk, or regarding oneself superior to others which is termed as pride, or having a firm and definite intention to consume wine. These are such actions for which one is accountable.
– The second category is of those actions that are carried out involuntarily, such as an evil thoughts coming into the mind unintentionally. When the Sahaaba Radiallahu Anhum heard the above Tafseer they were at ease that there isn’t any punishment or reward on unintentional whispers of Shaytaan and thoughts.
After understanding the above, you should understand that what you had experienced was simply a thought. You did not even entertain it any further or build on it, instead you despised the thought and showed concern and remorse by thinking that it was wrong. This (showing remorse) is a sign of Imaan according to one Hadith.
In conclusion, on the basis of an involuntary thought of this nature, one does not lose one’s Imaan.