حَدَّثَنَا عُثْمَانُ بْنُ أَبِي شَيْبَةَ، حَدَّثَنَا جَرِيرٌ، عَنِ الأَعْمَشِ، عَنْ أَبِي ظَبْيَانَ، عَنِ ابْنِ عَبَّاسٍ، قَالَ أُتِيَ عُمَرُ بِمَجْنُونَةٍ قَدْ زَنَتْ فَاسْتَشَارَ فِيهَا أُنَاسًا فَأَمَرَ بِهَا عُمَرُ أَنْ تُرْجَمَ فَمُرَّ بِهَا عَلَى عَلِيِّ بْنِ أَبِي طَالِبٍ رِضْوَانُ اللَّهِ عَلَيْهِ فَقَالَ مَا شَأْنُ هَذِهِ قَالُوا مَجْنُونَةُ بَنِي فُلاَنٍ زَنَتْ فَأَمَرَ بِهَا عُمَرُ أَنْ تُرْجَمَ ‏.‏ قَالَ فَقَالَ ارْجِعُوا بِهَا ثُمَّ أَتَاهُ فَقَالَ يَا أَمِيرَ الْمُؤْمِنِينَ أَمَا عَلِمْتَ أَنَّ الْقَلَمَ قَدْ رُفِعَ عَنْ ثَلاَثَةٍ عَنِ الْمَجْنُونِ حَتَّى يَبْرَأَ وَعَنِ النَّائِمِ حَتَّى يَسْتَيْقِظَ وَعَنِ الصَّبِيِّ حَتَّى يَعْقِلَ قَالَ بَلَى ‏.‏ قَالَ فَمَا بَالُ هَذِهِ تُرْجَمُ قَالَ لاَ شَىْءَ ‏.‏ قَالَ فَأَرْسِلْهَا ‏.‏ قَالَ فَأَرْسَلَهَا ‏.‏ قَالَ فَجَعَلَ يُكَبِّرُ ‏.‏

Narrated Ali ibn AbuTalib: Ibn Abbas said: A lunatic woman who had committed adultery was brought to Umar. He consulted the people and ordered that she should be stoned. Ali ibn AbuTalib passed by and said: What is the matter with this (woman)? They said: This is a lunatic woman belonging to a certain family. She has committed adultery. Umar has given orders that she should be stoned. He said: Take her back. He then came to him and said: Commander of the Faithful, do you not know that there are three people whose actions are not recorded: a lunatic till he is restored to reason, a sleeper till he awakes, and a boy till he reaches puberty? He said: Yes. He then asked: Why is it that this woman is being stoned? He said: There is nothing. He then said: Let her go. He (Umar) let her go and began to utter: Allah is most great. Translation Not Available

Book Ref: Sunan Abi Dawud Book 40 Hadith 4399
Web Ref:  Sunan Abi Dawud Book 39 Hadith 4385