It is not permissible for the zaani (fornicator or adulterer) to marry the zaaniyah (fornicatress or adulteress) except after repenting because Allah, may He be exalted, says (interpretation of the meaning):
The adulterer marries not but an adulteress or a Mushrikah and the adulteress none marries her except an adulterer or a Muskrik. Such a thing is forbidden to the believers (of Islamic Monotheism)
Repentance is achieved by regretting (what one has done) and resolving not to go back to the sin. This may have happened in the case asked about here, hence they gave up zina and wanted to live a clean life that is pleasing to Allah, as you say, and they wanted to be on the safe side by making sure that she was not pregnant as a result of something haraam.
The fuqaha' differed concerning the validity of a marriage between two who committed zina, if the marriage was done before they repented. The majority are of the view that it is valid, but the Hanbalis are of the view that it is not valid, and this is the more correct view. See question no. 85335
What is required in that case is to repeat the marriage contract. The matter does not require a talaaq (divorce); rather it is a repeat of the marriage contract, in which the woman's wali (guardian) may be her Muslim father, brother or any other male relative on the father's side, so long as he is Muslim. If she has no male Muslim relatives, then the imam of the Islamic Centre may act as her guardian for the purpose of marriage, in the presence of two Muslim witnesses.
It is not essential to tell the one who does the marriage contract of the details of the situation; it is possible to use double entendres and to say that they want to repeat the marriage contract because of some uncertainty about its validity, because they got married without a wali, or for some other appropriate reason, or because it was done in another city or country, and so on, because the Muslim is enjoined to conceal his faults and mistakes.
The children who were born under the previous marriage contract should be attributed to the husband, because they were born in a marriage that both spouses believed to be valid.
And Allah knows best.
Reproduced from Islam QA