Abdullah bin Abbas reported,

Ali bin Abu Talib passed by an insane woman of such-and-such tribe who had committed adultery, and Umar had ordered her to be stoned. Ali sent her back and said to Umar, "Commander of the Faithful, are you going to stone this woman?"Umar replied, "Yes."Ali said, "Do you not remember that the Messenger of Allah ﷺ said, 'The pen has been lifted from three: the insane person whose reason is overcome, the sleeper until he wakes, and the child until he reaches puberty'?"Umar said, "You have spoken the truth," and he let her go.

Azami 6974

Sahih

عن ابن عباس قال

مر علي بن أبي طالب بمجنونة بني فلان قد زنت، أمر عمر برجمها، فردها علي، وقال لعمر: يا أمير المؤمنين أترجم هذه؟ قال: نعم، قال: أو ما تذكر أن رسول الله ﷺ قال: رفع القلم عن ثلاثة، عن المجنون المغلوب على عقله، وعن النائم حتى يستيقظ، وعن الصبي حتى يحتلم قال: صدقت، فخلى عنها.

الأعظمي 6974صحيح
Contents
Reference
Commentary
Ayat
Collection
Jami al-Kamil
Book
Legal punishments
Chapter
Hadd of zina
Section
Warding off the legal punishment from an insane woman
Numbering
Jami al-Kamil 6974 (2nd edition)
Azami 6974