The Prophet ﷺ said, "The pen has been lifted from three. From the sleeper until he wakes, from the child until he reaches puberty, and from the insane until he regains his sanity."
حدثنا موسى بن إسمعيل حدثنا وهيب عن خالد عن أبي الضحى
عن النبي ﷺ قال رفع القلم عن ثلاثة عن النائم حتى يستيقظ وعن الصبي حتى يحتلم وعن المجنون حتى يعقل
[Its isnad is daif]. Bayhaqi related it, 3/83 and 7/359, from the hadith of Abu Dawud, with the same wording. The chain is disconnected, and the hadith has corroborating narrations, see no. 4400. The hadith of Ibn Jurayj was related by Ibn Majah, no. 2042.