Musnad Ahmad 940
It was narrated from ‘Ali (رضي الله عنه):
I heard the Messenger of Allah (ﷺ) say: `The Pen has been lifted from three: from the child until he reaches puberty, from the sleeper until he wakes up and from the insane until he regains his sanity.”
حَدَّثَنَا هُشَيْمٌ، أَنْبَأَنَا يُونُسُ، عَنِ الْحَسَنِ، عَنْ عَلِيٍّ، رَضِيَ اللَّهُ عَنْهُ سَمِعْتُ رَسُولَ اللَّهِ صَلَّى اللَّهُ عَلَيْهِ وَسَلَّمَ يَقُولُ رُفِعَ الْقَلَمُ عَنْ ثَلَاثَةٍ عَنْ الصَّغِيرِ حَتَّى يَبْلُغَ وَعَنْ النَّائِمِ حَتَّى يَسْتَيْقِظَ وَعَنْ الْمُصَابِ حَتَّى يُكْشَفَ عَنْهُ‏.‏