Ibrahim Nakha'i (may Allah have mercy on him) said: If a madman regains his senses at times, then in the state of sanity his emancipation, divorce, punishment (hadd), and purchase are valid.
Hadith Referenceسنن سعید بن منصور / كتاب الطلاق / 2303
Hadith Takhrij«أخرجه سعيد بن منصور فى «سننه» ترقيم الدرالسلفية برقم:، 1122، 1126»