(The evidence for this) is the narration that Ibn Lahi'ah narrated from Yazid bin Abi Habib, from Ata' bin Abi Rabah (may Allah have mercy on him), that: "Al-Muttalib bin Abi Wada'ah and Ya'la bin Umayyah (may Allah be pleased with them) held a testimony from the time of Ignorance (Jahiliyyah); then in (the era of) Islam they were brought before Sayyiduna Mu'awiyah (may Allah be pleased with him), and he accepted it (the testimony)."
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