Hadithcore
Hadith #2113490

Narrated 'Aishah (RA):

The Prophet (ﷺ) said: "There are three people whose actions are not recorded, a sleeping person till he awakes, a child till he is a grown up, and an insane person till he is restored to reason or recovers his sense." [Reported by Ahmad and al-Arba'a, except at-Tirmidhi. al-Hakim graded it Sahih (authentic)].

وَعَنْ عَائِشَةَ رَضِيَ اَللَّهُ عَنْهَا, عَنْ اَلنَّبِيِّ ‏- صلى الله عليه وسلم ‏-قَالَ: { رُفِعَ اَلْقَلَمُ عَنْ ثَلَاثَةٍ: عَنِ اَلنَّائِمِ حَتَّى يَسْتَيْقِظَ, وَعَنِ اَلصَّغِيرِ حَتَّى يَكْبُرَ, وَعَنِ اَلْمَجْنُونِ حَتَّى يَعْقِلَ, أَوْ يَفِيقَ } رَوَاهُ أَحْمَدُ, وَالْأَرْبَعَةُ إِلَّا اَلتِّرْمِذِيَّ وَصَحَّحَهُ اَلْحَاكِمُ.‏ [1]‏ .‏

References2 variants
Sunnah.com reference
Book 8, Hadith 141
Arabic/English book reference
Book 8, Hadith 1096