Sayyiduna Ali (may Allah be pleased with him) narrates from the Prophet (peace and blessings be upon him) that he (peace and blessings be upon him) said: "The pen has been lifted from three: the sleeper until he wakes up, the child until he reaches puberty, and the insane until he regains his reason."
And Imam al-Shafi'i (may Allah have mercy on him) took the hadith of Ibn Umar (may Allah be pleased with him) about being permitted to fight as evidence, and it has already passed.
Hadith Referenceالسنن الكبرى للبيهقي / كتاب الخلع والطلاق / 15109
Abis bin Rabi'ah (may Allah have mercy on him) said that Sayyiduna Ali (may Allah be pleased with him) said: "Every divorce is valid except the divorce of the mentally deranged (ma'tuh)."
(b) Al-Sha'bi, al-Hasan and Ibrahim (may Allah have mercy on them) all said that a child's divorce and freeing of a slave are not valid until he reaches puberty.
(c) Jabir bin Zayd, Ibrahim and Abu Qilabah (may Allah have mercy on them) did not consider valid the divorce of a person suffering from a lung disease (birsam). Al-Sha'bi and Ibrahim (may Allah have mercy on them) said about a person who divorces and frees a slave in his sleep: "It is nothing."
Hadith Referenceالسنن الكبرى للبيهقي / كتاب الخلع والطلاق / 15110