Umar bin Khattab once intended to stone an insane woman.Ali said to him, "You have no right to do that. I heard the Messenger of Allah ﷺ say, '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 or regains his sanity.'"So Umar withheld the punishment from her.
حدثنا محمد بن جعفر حدثنا سعيد عن قتادة
أن عمر بن الخطاب أراد أن يرجم مجنونة فقال له علي ما لك ذلك قال سمعت رسول الله ﷺ يقول رفع القلم عن ثلاثة عن النائم حتى يستيقظ وعن الطفل حتى يحتلم وعن المجنون حتى يبرأ أو يعقل فأدرأ عنها عمر رضي الله عنه