Overall meaning :
Allah Almighty orders His servants—long before he laid down the punishment for adultery—to confine any of their women who commit adultery to their houses, whether or not they are married, until death overtakes them or until Allah grants them some other way out, after four Muslim men of known probity and integrity have testified to their guilt.
He further instructs the faithful to inflict harm on men or women who commit adultery by scolding or beating them, or doing them any other type of harm, for that matter. If, however, they repent and mend their ways, the believers ought to leave them alone. Surely Allah is All-Forgiving and All-Merciful. These provisions are all abrogated.
Then He explains that He pardons those who commit sins in ignorance and then quickly turn to Him in penitence before they are overtaken by death. It is these whose repentance He will accept, and Allah is All-Knowing, All-Wise. As for those who persistently commit sinful deeds and repent only when death comes to them, He will not accept their repentance, just as He will not in any way accept the repentance of those who die unbelievers. For these, He has prepared a painful punishment.