The saying of Allah, exalted be His praise: "And those who accuse chaste women and then do not bring four witnesses, flog them with eighty (80) lashes and never accept their testimony, and it is they who are the defiantly disobedient." [Surah al-Nur: 4] "Except those who repent after that and reform, then indeed Allah is Most Forgiving, Most Merciful." [Surah al-Nur: 5]
Imam al-Shafi'i (may Allah have mercy on him) said: "An exception that comes in the course of speech applies to both the beginning and the end of the speech, according to the position of all the people of fiqh, unless a hadith distinguishes between them."
Imam al-Shafi'i (may Allah have mercy on him) said: "And indeed there is a hadith (also) on this."
Sufyan bin Uyaynah (may Allah have mercy on him) said: I heard al-Zuhri (may Allah have mercy on him) say: The people of Iraq claim that the testimony of one who has been given a hadd punishment is not permissible. I inform you that Umar bin al-Khattab (may Allah be pleased with him) said to Abu Bakrah (may Allah be pleased with him): Repent, and your testimony will be accepted; or: If you repent, your testimony will be accepted.
(b) The huffaz narrate it from Hadrat Sa'id (may Allah have mercy on him) without doubt, and in it is the addition that Hadrat Umar bin al-Khattab (may Allah be pleased with him) asked the three to repent; two repented and their testimony was accepted, and Abu Bakrah (may Allah be pleased with him) refused, so his testimony was rejected.
Hadith Referenceالسنن الكبرى للبيهقي / كتاب الشهادات / 20545