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.
مر علي بن أبي طالب بمجنونة بني فلان قد زنت، أمر عمر برجمها، فردها علي، وقال لعمر: يا أمير المؤمنين أترجم هذه؟ قال: نعم، قال: أو ما تذكر أن رسول الله ﷺ قال: رفع القلم عن ثلاثة، عن المجنون المغلوب على عقله، وعن النائم حتى يستيقظ، وعن الصبي حتى يحتلم قال: صدقت، فخلى عنها.
Abu Dawud (4401) narrated it, and Ibn Khuzayma (1003) and Ibn Hibban (143) graded it sahih, and Bayhaqi (8/264) narrated it from him. All of them narrated it through Jareer bin Hazim, from Amash, from Abu Dhubyan, from Ibn Abbas, who related it. Its isnad is sahih.Shuba and Ibn Numayr narrated it from Amash as a stopped narration (mawquf), and precedence is given to whoever added more.As for what Imam Ahmad (1328) and Abu Dawud (4402) narrated through the route of Ata bin Saaib, from Abu Dhubyan, that Umar bin Khattab was brought a woman and he mentioned something similar, this contains a break in the chain, for Abu Dhubyan did not meet Umar bin Khattab.The matter on which there is no disagreement among the scholars is that there is no hadd punishment upon the insane person. It has been reported in the story of Maiz Aslami that the Prophet ﷺ asked his people, "Is he insane?" and he even said to him, "Do you suffer from madness?" But could it have been hidden from Umar that the hadd punishment is not carried out on the insane person? I doubt that. Perhaps she would become insane at times and regain her senses at other times. Her act of zina occurred while she was in a lucid state, and Umar did not know that she would become insane at times and regain her senses at other times. So Ali held the view that insanity constitutes a doubt that averts the hadd punishment from whoever is afflicted with it, even if it occurred during a lucid state, and Umar accepted this from him .