Praise be to Allah.
Punishment is expiation for sins
The carrying out of the hadd punishment for a sin for which that punishment has been prescribed is expiation for that sin.
Repentance is expiation for sins
Sincere repentance from sin is also expiation for sin, and “the one who repents from sin is like the one who did not sin.” And Allah will turn his bad deeds into good deeds.
If he is sincere in his repentance , and prays a great deal for forgiveness, then he does not have to confess so that the hadd punishment may be carried out on him. Rather repentance is sufficient, in sha Allah.
Allah says (interpretation of the meaning):
“And those who invoke no other ilah (god) along with Allah, nor kill such a 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.
And whosoever repents and does righteous good deeds; then verily, he repents towards Allah with true repentance.” [al-Furqan 25:68-71]
It was narrated from ‘Ubadah ibn al-Samit (may Allah be pleased with him) that the Messenger of Allah (peace and blessings of Allah be upon him) said: “Give me your oath of allegiance and your pledge that you will not associate anything in worship with Allah, or steal, or commit adultery, or kill your children, or utter slander, intentionally forging falsehood (i.e. by making illegal children belonging to their husbands) [cf. al-Mumtahanah 60:12], or disobey with regard to anything that is good. Whoever among you fulfils this pledge, Allah will reward him, and whoever does any of these things and is punished in this world, that will be an expiation for him. Whoever does any of these things and Allah conceals it for him, then it is up to Allah: if He wills He will forgive him and if He wills He will punish him.” Narrated by al-Bukhari, 18; Muslim, 1709.
In Sahih Muslim (1695) it says that when Ma’iz came to the Prophet (peace and blessings of Allah be upon him) and confessed that he had committed zina and said, “Purify me (i.e., carry out the hadd punishment on me)”, he said to him, “Woe to you, go back and ask Allah for forgiveness and repent to Him.”
“This hadith indicates that the burden of sin is lifted from one who repents from major sins , and this is according to the consensus of the Muslims.”
Al-Hafiz Ibn Hajar said:
“From this case – i.e. the case of Ma’iz when he confessed zina – it may be understood that it is mustahabb for the one whose case is similar to repent to Allah and to conceal himself and not mention his sin to anyone… This was affirmed by al-Shafi'i who said: I prefer for the one who has committed a sin and been concealed by Allah to conceal it himself and to repent.” (Fath al-Bari, 12/124, 125)
And it was narrated from ‘Abd-Allah ibn ‘Umar (may Allah be pleased with him) that the Messenger of Allah (peace and blessings of Allah be upon him) said: “Avoid these sins that Allah has forbidden, but whoever does any of them, let him conceal himself with the concealment of Allah and repent to Allah, for whoever tells us of what he has done, we will carry out (the punishment prescribed in) the Book of Allah on him.”
It was also narrated by al-Hakim in al-Mustadrak ‘ala al-Sahihayn (4/425) and by al-Bayhaqi (8/330); classed as sahih by al-Albani in Sahih al-Jami’, 149.
And Allah knows best.