Muhammad bin Salim (may Allah have mercy on him) narrates from al-Sha'bi (may Allah have mercy on him) that when a child witnesses something before reaching puberty, then gives testimony after reaching puberty, it is valid; likewise a Jew or Christian who witnesses in the state of shirk and then becomes Muslim, and likewise a slave who is later freed and then gives testimony: their testimony is permissible.
Hadith Referenceالسنن الكبرى للبيهقي / كتاب الشهادات / 20633