The Prophet ﷺ said, "The pen has been lifted from three: from the sleeper until he awakens, from the child until he reaches maturity, and from the insane until he regains his reason or recovers."
أخبرنا يعقوب بن إبراهيم قال حدثنا عبد الرحمن بن مهدي قال حدثنا حماد بن سلمة عن حماد عن إبراهيم عن الأسود
عن النبي ﷺ قال رفع القلم عن ثلاث عن النائم حتى يستيقظ وعن الصغير حتى يكبر وعن المجنون حتى يعقل أو يفيق
[Hasan] Reported by Ibn Majah, Divorce, Chapter on the divorce of the insane, the minor, and the sleeping person, no. 2041, from the hadith of Ibn Mahdi, with the same wording. It is also in Kubra, no. 5625. Ibn Hibban graded it sahih, no. 1496, as did Hakim, on the condition of Muslim, 2/59, and Dhahabi agreed with him. The hadith has corroborating narrations in Abu Dawud, no. 4400, and elsewhere.