A insane person is not to be stoned
In the narration reported from Abu Hurairah (may Allah be pleased with him), a man came to the mosque and testified four times before the Messenger of Allah ﷺ that he had committed adultery. So the Messenger of Allah ﷺ called him and asked:
أبك جنون
“Are you insane?”
He said, “No.” The Prophet ﷺ said: “Go and stone him.”
[Bukhari: 6815, Kitab al-Hudud: Bab la yurjamu al-majnun wal-majnunah]
Certainly, the purpose of the Prophet’s ﷺ question was that if he were insane, the punishment of stoning would be dropped from him.