Praise be to Allah.
Zina (fornication, adultery) is a serious crime and a major sin which takes away the quality of faith from a person, and exposes him to punishment and humiliation unless he repents. Allaah says (interpretation of the meaning):
“And come not near to unlawful sex. Verily, it is a Faahishah (i.e. anything that transgresses its limits: a great sin, and an evil way that leads one to hell unless Allaah Forgives him)”
and the Prophet (peace and blessings of Allaah be upon him) said: “No adulterer is a believer at the time when he is committing adultery” Narrated by al-Bukhaari (2475) and Muslim (57).
And he (peace and blessings of Allaah be upon him) said: “If a man commits zina, faith comes out of him and hovers over him like a cloud, then when he stops, faith returns to him.” Narrated by Abu Dawood (4960) and al-Tirmidhi (2625); classed as saheeh by al-Albaani in Saheeh Abi Dawood.
The Prophet (peace and blessings of Allaah be upon him) has told us of the punishment that those who commit zina will receive in their graves before the Hour begins, and that they will be punished with fire. Narrated by al-Bukhaari (1320).
Because of the abhorrent nature of this crime, Allaah has decreed that the punishment for it should be stoning to death if the person is married and flogging if he was not married.
The one who is faced with any such thing should hasten to repent to Allaah and do a lot of good deeds, in the hope that Allaah will forgive him. Allaah says (interpretation of the meaning):
“And those who invoke not any other ilaah (god) along with Allaah, nor kill such person as Allaah has forbidden, except for just cause, nor commit illegal sexual intercourse ___ and whoever does this shall receive the punishment.
69. The torment will be doubled to him on the Day of Resurrection, and he will abide therein in disgrace;
70. Except those who repent and believe (in Islamic Monotheism), and do righteous deeds; for those, Allaah will change their sins into good deeds, and Allaah is Oft‑Forgiving, Most Merciful”
“And verily, I am indeed forgiving to him who repents, believes (in My Oneness, and associates none in worship with Me) and does righteous good deeds, and then remains constant in doing them (till his death)”
They must also conceal themselves with the concealment of Allaah, and not tell anyone about that, The Prophet (peace and blessings of Allaah be upon him) said: “Avoid these filthy things that Allaah has forbidden. Whoever has done any of them, let him conceal himself with the concealment of Allaah, may He be glorified and exalted.” Narrated by al-Bayhaqi and classed as saheeh by al-Albaani in al-Silsilah al-Saheehah, no. 663.
It is not permissible for a man or woman who has committed zina to get married until after he or she has repented, because Allaah says (interpretation of the meaning):
“The adulterer — fornicator marries not but an adulteress — fornicatress or a Mushrikah; and the adulteress –fornicatress, none marries her except an adulterer — fornicater or a Mushrik [and that means that the man who agrees to marry (have a sexual relation with) a Mushrikah (female polytheist, pagan or idolatress) or a prostitute, then surely, he is either an adulterer — fornicator, or a Mushrik (polytheist, pagan or idolater). And the woman who agrees to marry (have a sexual relation with) a Mushrik (polytheist, pagan or idolater) or an adulterer — fornicator, then she is either a prostitute or a Mushrikah (female polytheist, pagan, or idolatress)]. Such a thing is forbidden to the believers (of Islamic Monotheism)”
If they had both repented to Allaah before getting married, and they regretted the haraam things that they had done, then their marriage is valid. But if they did the marriage contract before they repented, then the marriage is not valid and they have to repent to Allaah and regret what they have done, and resolve not to do such a thing again, then they should make a new marriage contract. This has been discussed in the answer to question no. 85335.
And Allaah knows best.