Sunan Abi Dawud 4401
Grading supplied with this record: Sahih (Al-Albani)
Narration text is preserved in its supplied Arabic and English. Translated interfaces and reading guides do not add narration translations in other languages.
رُفِعَ الْقَلَمُ عَنْ ثَلاَثَةٍ عَنِ الْمَجْنُونِ الْمَغْلُوبِ عَلَى عَقْلِهِ حَتَّى يُفِيقَ وَعَنِ النَّائِمِ حَتَّى يَسْتَيْقِظَ وَعَنِ الصَّبِيِّ حَتَّى يَحْتَلِمَ "
Narrated Ali ibn Abu Talib:
Ibn Abbas said: A lunatic woman passed by Ali ibn Abu Talib. He then mentioned the rest of the tradition to the same effect as Uthman mentioned. This version has: Do you not remember that the Messenger of Allah (ﷺ) has said: There are three whose actions are not recorded: a lunatic whose mind is deranged till he is restored to consciousness, a sleeper till he awakes, and a boy till he reaches puberty?
Full reference and source
Sunan Abi Dawud 4401 In-book : Book 40, Hadith 51 English translation : Book 39, Hadith 4387
View source on Sunnah.com (opens in a new tab)