Sayyiduna Abdullah bin Abbas (may Allah be pleased with them both) narrates that Sayyiduna Ali (may Allah be pleased with him) passed by an insane woman of such-and-such a tribe who had committed adultery and was being stoned. Sayyiduna Ali (may Allah be pleased with him) said to Sayyiduna Umar (may Allah be pleased with him): "O Commander of the Believers, did you order the stoning of so-and-so?" He said: "Yes." He said: "Do you not remember the saying of the Messenger of Allah (peace and blessings be upon him), which he (peace and blessings be upon him) said: 'The pen has been lifted from three: from the sleeper until he wakes, from the child until he reaches puberty, and from the insane until he recovers'?" Sayyiduna Umar (may Allah be pleased with him) said: "Yes." Then he gave orders concerning her, and she was released.
Hadith Referenceالسنن الكبرى للبيهقي / كتاب الصيام / 8307