The Prophet ﷺ said: There are three (persons) whose actions are not recorded: a sleeper till he awakes, a boy till he reaches puberty, and a lunatic till he comes to reason. Abu Dawud said: Ibn Juraij has transmitted it from Al-Qasim b. Yazid on the authority of 'Ali from the Prophet ﷺ. This version adds: "and an old man who is feeble-minded." (Using translation from Abū Dāʾūd 4403)
عَنِ النَّبِيِّ ﷺ رُفِعَ الْقَلَمُ عَنْ ثَلَاثَةٍ عَنِ الصَّبِيِّ حَتَّى يَحْتَلِمَ وَعَنِ الْمَعْتُوهِ حَتَّى يُفِيقَ وَعَنِ النَّائِمِ حَتَّى يَسْتَيْقِظَ