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.
Allah says in Quran: “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 Allah Forgives him)”
and the Prophet (peace and blessings of Allah 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 Allah 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 Allah 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, Allah 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 Allah and do a lot of good deeds, in the hope that Allah will forgive him.
Allah says in Quran: “And those who invoke not any other ilaah (god) along with Allah, nor kill such person as Allah has forbidden, except for just cause, nor commit illegal sexual intercourse and whoever does this shall receive the punishment.
The torment will be doubled to him on the Day of Resurrection, and he will abide therein in disgrace;
Except those who repent and believe (in Islamic Monotheism), and do righteous deeds; for those, Allah will change their sins into good deeds, and Allah is Oft‑Forgiving, Most Merciful”
They must also conceal themselves with the concealment of Allah, and not tell anyone about that, The Prophet (peace and blessings of Allah be upon him) said: “Avoid these filthy things that Allah has forbidden. Whoever has done any of them, let him conceal himself with the concealment of Allah, 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.
Allah says in Quran: “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 Allah 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 Allah and regret what they have done, and resolve not to do such a thing again.
And Allah knows best.