The Quranic injunctions with regards to those who commit zina were revealed in stages.
The wisdom behind this was to make these injunctions acceptable to the new converts to Islam who often engaged in zina during the days of Jahiliyah (ignorance).
The first revelation concerning the punishment of zina was that a woman guilty of zina was to be confined to her home until she died (An-Nisaa 4:15).
The second revelation covered both men and women and was not very specific regarding punishment:
[And as for the two who are guilty of indecency from among you, give them both a punishment; then if they repent and amend, turn aside from them; surely Allah is Oft-returning (to mercy), the Merciful.] (An-Nisaa 4:16)
Allah Almighty then revealed:
[(As for) the fornicatress and the fornicator, flog each of them, (giving) a hundred stripes, and let not pity for them detain you in the matter of obedience to Allah and the last day.] (An-Nur 24:2)
Know that punishment for this crime of zina acts as atonement for this sin. The idea behind the harsh and severe punishment does not contradict the spirit of Islam; it actually serves as a deterrent in society. It protects a persons family lineage and the spread of moral decadence and disease in society.
When people realize the graveness of their sin, and that its punishment is most humiliating and painful, very few would dare to commit it.
Marriage to a Person Guilty of Zina
Marriage between two who are guilty of zina is permissible as per what Allah Almighty says:
[The fornicator shall not marry any but a fornicatress or idolatress, and (as for) the fornicatress, none shall marry her but a fornicator or an idolater; and it is forbidden to the believers."] (An-Nur 24:3)
There is a difference of opinion among the scholars with regards to a chaste man marrying an adulteress who has not repented or vice versa. Some of them said that it is not lawful.
This is the opinion of Ali, Al-Baraa, Aishah, and Masud (may Allah be pleased with them all).
The majority of scholars, including Abu Bakr, Umar or Uthman, and Ibn Abbas (may Allah be pleased with them all), on the other hand, permitted marriage with an adulterer, adding however, that marriage to a chaste and pure person was more virtuous.
Repentance
One might think that the only way a person guilty of zina can be forgiven is by undergoing the prescribed punishment (hadd), but scholars have said that a person who commits a sin should repent to Allah Almighty.
The repentance should be sincere, and the guilty person should perform lots of righteous acts and acts of worship. Furthermore, the person should feel remorse and have no intention of ever committing the sin again.
The repentance will not be accepted if it is done during the throes of death, as Allah Most High says
[And repentance is not for those who go on doing evil deeds, until when death comes to one of them, he says: Surely now I repent; nor (for) those who die while they are unbelievers.] (An-Nisaa' 4:18)
There are many ways that Muslims can protect themselves from zina. Salah (prayer), both obligatory and supererogatory, is one of the strongest defenses against zina. Allah Almighty says
[Recite that which has been revealed to you of the Book and keep up prayer; surely prayer keeps (one) away from indecency and evil, and certainly the remembrance of Allah is the greatest.] (Al-Ankabut 29:45)
Regular fasting is another way of suppressing sexual desires, as Allahs Messenger prescribed it for young people who could not afford to get married.
Another way to keep away from zina is by reminding yourself how you would abhor and dislike it for your mother, daughter, sister, brother, and aunt.
This was how Prophet Muhammad explained it to a man who came seeking permission to commit zina. The Prophet told him to remember that Satan watches and waits for you to be distant from your Muslim brethren, then he makes his attack. And so among the things that will deter you from zina is to always be in the company of righteous people who will remind you of Allah Almighty.
The Messenger of Allah (peace and blessings be upon him) said in the hadith collection of Abu Dawud, "Indeed the wolf devours the lone sheep." Remember that saying "no" to someone who invites you to commit zina will secure you a place of shelter under the shade of Allah's throne on the day when their will be no shelter except His.
We ask Allah Most High to protect us from the evil of zina, to accept out righteous actions, and to shower us with His bounties in this life and in the hereafter.