The Messenger of Allah ﷺ said, "The pen has been lifted from three: from the sleeper until he wakes, from the child until he reaches maturity, and from the mentally impaired until he regains his reason."
حدثنا محمد بن يحيى القطعي البصري حدثنا بشر بن عمر حدثنا همام عن قتادة عن الحسن البصري
أن رسول الله ﷺ قال رفع القلم عن ثلاثة عن النائم حتى يستيقظ وعن الصبي حتى يشب وعن المعتوه حتى يعقل
Sourcing, [hasan]. Nasai also recorded it in Al-Kubra, no. 7346, from the hadith of Hammam through the same route. This hadith has corroborating narrations in Abu Dawud, no. 4403, 4398, Ibn Khuzayma, 22/102, 4/348, Ibn Hibban, no. 1496, Hakim, 2/59, 4/389, and others. It also has a mawquf corroborating report that is sahih and carries the ruling of a marfu hadith.The hadith of Ata bin Saaib is found in Abu Dawud, no. 4402, and the hadith of Amash is also there, no. 4399. On this topic there is also a report from Ayesha [Abu Dawud, 398].