Praise be to Allah.
If a person has intercourse with his wife after the first stage of exiting ihram and before doing Tawaaf al-ifaadah, then his Hajj is not rendered invalid by that, but he has committed sin by doing it. He has to repent and seek forgiveness from that, and he should go out of the boundary of the Haram zone in order to enter ihram anew, and do tawaaf al-ifaadah.
He also has to slaughter a sheep, and distribute the meat to the poor of the Haram, and not eat any of it himself.
If his wife was in ihram and had intercourse with him willingly, then she must do the same as him, but if he compelled her to do that, then she does not have to do anything.
It says in al-Mawsoo‘ah al-Fiqhiyyah (2/192):
(The scholars) are unanimously agreed that intercourse after the first stage of exiting ihram does not invalidate Hajj… but there was a difference of opinion as to the necessary penalty. The Hanafis, Shaafa‘is and Hanbalis are of the view that he must offer a sheep. They based their view on the fact that the offence is of a lesser degree, because of having passed the first stage of exiting ihram, in the case of men.
Maalik said – and it was also a view held by some of the Shaafa‘is and Hanbalis – : He has to offer a camel. Al-Baaji explained it as being because of the seriousness of the sin when one has still (not fully) exited ihram.
Maalik and the Hanbalis regarded it as obligatory for the one who commits this offence after the first stage of exiting ihram and before doing tawaaf al-ifaadah to go out of the Haram zone, and do (another) ‘umrah, because of the words of Ibn ‘Abbaas to that effect … but the Hanafis and Shaafa‘is did not regard that as obligatory. End quote.
Shaykh Muhammad ibn Ibraaheem (may Allah have mercy on him) said:
Intercourse after exiting ihram does not invalidate Hajj, whether it was ifraad (Hajj on its own) or qiraan (‘umrah and Hajj together, without exiting ihram in between). Rather it only invalidates ihram, in the sense that it is not valid for him to do tawaaf al-ifaadah until he goes out of the Haram zone and enters ihram, then comes to Makkah and does tawaaf al-ifaadah in a valid state of ihram.
He also has to sacrifice a sheep, to be slaughtered in the Haram and the meat given to the poor; he should not eat any of it. His wife must also offer a fidyah of another sheep, if she did that willingly, but if she was forced, then she does not have to do anything. End quote.
Fataawa wa Rasaa’il Muhammad ibn Ibraaheem (5/203-204)
Shaykh Ibn ‘Uthaymeen (may Allah have mercy on him) said:
A man had intercourse before tawaaf al-ifaadah, after stoning the Jamrah and shaving his head; what should he do?
He does not have to do anything except offer a sacrifice to be given in charity to the poor. And he has to enter ihram again from outside the Haram zone, so that can do tawaaf in ihram. End quote.
Liqa’ al-Baab al-Maftooh (90/17)
If he did not go out of the Haram zone in order to renew his ihram, we hope that his tawaaf is still valid. Shaykh Ibn Baaz (may Allah have mercy on him) was asked:
A man did not do tawaaf al-ifaadah and he went back to his country and had intercourse with his wife. What does he have to do?
He has to repent to Allah, may He be glorified and exalted, and he has to offer a sacrifice, to be slaughtered in Makkah and given to the poor. He also has to go back and do tawaaf al-ifaadah, because his having intercourse with his wife before doing tawaaf al-ifaadah is not permissible and a sacrifice must be offered for that. The correct view is that a sheep is sufficient, or one seventh of a camel or one seventh of a cow. End quote.
Majmoo‘ Fataawa Ibn Baaz (17/180)
And Allah knows best.