Musnad Ahmad 1183
It was narrated from Al-Hasan that `Umar bin Al-Khattab (رضي الله عنه) wanted to stone an insane woman, but ‘Ali said to him:
You do not have the right to do that. He said: I heard the Messenger of Allah (ﷺ) say: “The Pen has been lifted from three: from the sleeper until he wakes up, from the child until he reaches adolescence, and from the insane person until he recovers, or comes to his senses.` So `Umar (رضي الله عنه) pardoned her.
حَدَّثَنَا مُحَمَّدُ بْنُ جَعْفَرٍ، حَدَّثَنَا سَعِيدٌ، عَنْ قَتَادَةَ، عَنِ الْحَسَنِ، أَنَّ عُمَرَ بْنَ الْخَطَّابِ، أَرَادَ أَنْ يَرْجُمَ، مَجْنُونَةً فَقَالَ لَهُ عَلِيٌّ مَا لَكَ ذَلِكَ قَالَ سَمِعْتُ رَسُولَ اللَّهِ صَلَّى اللَّهُ عَلَيْهِ وَسَلَّمَ يَقُولُ رُفِعَ الْقَلَمُ عَنْ ثَلَاثَةٍ عَنْ النَّائِمِ حَتَّى يَسْتَيْقِظَ وَعَنْ الطِّفْلِ حَتَّى يَحْتَلِمَ وَعَنْ الْمَجْنُونِ حَتَّى يَبْرَأَ أَوْ يَعْقِلَ فَأَدْرَأَ عَنْهَا عُمَرُ رَضِيَ اللَّهُ عَنْهُ‏.‏