Allah, glorified be His praise, says: "And those of your slaves who seek a contract (of emancipation), make a contract with them if you know any good in them." [Surah al-Nur: 33]
Imam al-Shafi'i (may Allah have mercy on him) said: "In this is evidence that Allah Almighty permitted a contract of emancipation (kitabah) only with a (slave) who understands what he is seeking, not with one who lacks the understanding to seek kitabah, such as a child or an insane person."
Hadith Referenceالسنن الكبرى للبيهقي / كتاب المدبر / Q21600
Sayyidah Aishah (may Allah be pleased with her) says that the Prophet (peace and blessings be upon him) said: "The pen has been lifted from three: from the sleeper until he wakes, from the insane until he recovers, and from the child until he reaches puberty."
Hadith Referenceالسنن الكبرى للبيهقي / كتاب المدبر / 21600