All perfect praise be to Allaah, The Lord of the worlds. I testify that there is none worthy of worship except Allaah and that Muhammad is His slave and Messenger.
The view that we adopt here at Islamweb is that the marriage of the man and woman who committed Zina (fornication or adultery) is not valid except after sincere repentance and making sure that the woman is not pregnant and that the child born out of wedlock is not traced to the fornicator under any circumstances.
However, some scholars are of the view that it is permissible for the fornicator to conduct a marriage contract with the woman whom he committed Zina with during her pregnancy and that the child is traced back to him as long as the woman is not someone else's wife and no one disputed with him regarding the tracing back of the child.
Ibn Qudaamah said:
“The illegitimate child is not traced back to the fornicator (or adulterer) according to the view of the majority of the scholars. Al-Hasan and Ibn Seereen said, 'The child is traced back to the fornicator if the Hadd (i.e. the corporal punishment determined by Islamic Law) of Zina is applied on him, and he inherits from him.' Ibraaheem said, 'He is traced back to him if he is lashed according to the Hadd that applies to him or if he had married the woman whom he had illegal sexual intercourse with.' Is-haaq said, 'The child is traced back to him.' ‘Urwah and Sulaymaan ibn Yassaar said the same thing. Ali ibn 'Aasim narrated from Abu Haneefah that he said, 'I do not see any harm if a man marries the woman with whom he impregnated from Zina during her pregnancy and that he conceals her sin and the child is traced back to him.'”
We recommend that the man and the woman (the fornicators) sincerely repent to Allaah and seek forgiveness and perform righteous deeds as much as possible. They should conceal their sin and not inform anyone about it because talking about the sin (informing others about it) is another sin that adds to the previous sin.
In case they sought a fatwa from someone who is trustworthy in his knowledge and piety, then it is permissible for them to act upon the fatwa that he issued to them, especially if acting upon that fatwa brings about a benefit or wards off a harm that could not be avoided otherwise.
Allaah knows best.