What is the ruling on one who commits sins unconsciously? For example, he has a blasphemous thought but when he realizes the meaning of what he said he immediately fears the wrath of Allah(Subhana wataala) and repents. I know that repentance erases sins but was he sinning at first at all?
وقد روى البخاري ومسلم عن أبي هُرَيْرَةَ رضي الله عنه قال: جاء نَاسٌ من أَصْحَابِ النبي صلى الله عليه وسلم فَسَأَلُوهُ إِنَّا نَجِدُ في أَنْفُسِنَا ما يَتَعَاظَمُ أَحَدُنَا أَنْ يَتَكَلَّمَ بِهِ قال: وقد وَجَدْتُمُوهُ ؟ قالوا نعم قال: ذَاكَ صَرِيحُ الْإِيمَانِ .
Rough translation: It was narrated from Bukhari and Muslim by way of Abu Hurayrah that some companions of the prophet asked him about thoughts that we cannot dare talk about. The prophet said: Did that happen to you, this is indeed a sure sign of belief.
Basically, being worried about this kind of thoughts is a sign of Emaan (being a believer)
وروى أيضاً عن أبي هُرَيْرَةَ رضي الله عنه قال: قال: رسول اللَّهِ صلى الله عليه وسلم: لَا يَزَالُ الناس يَتَسَاءَلُونَ حتى يُقَالَ هذا خَلَقَ الله الْخَلْقَ فَمَنْ خَلَقَ اللَّهَ، فَمَنْ وَجَدَ من ذلك شيئا فَلْيَقُلْ آمَنْتُ بِاللَّهِ. وفي رواية: فَلْيَسْتَعِذْ بِاللَّهِ وَلْيَنْتَهِ.
Rough translation: Narrated by Abu Hurayrah: The Prophet said (Sallallahu Alaihi Wassallam): People will keep asking until they come to ask "God created the creation, who then created God?" Whomever finds this in his thousands shall say "I believe in God" or in another narration "he shall seek refuge with God and stop thinking about it".
If a person committed sin unconsciously, then he/she should be repent to Allah and do promise to Allah that this sin will never repeat again. This is the true signs of Muslims that they repent to Allah after they committed the sins.
Allah says in the Qura'an:
And whoever repents and does righteousness good deeds, then verily, he has truly repented to Allah.
Chapter No. 25 (Surah Al-Furqan), Verse No. 71