Al-Bukhaari (may Allaah have mercy on him) narrated in his Saheeh (3/143, no. 3679) with his isnaad that ‘Ubaadah ibn al-Saamit, one of those who was present at Badr with the Messenger of Allaah (peace and blessings of Allaah be upon him), said that one of those who had been present at al-‘Aqabah told him:
The Messenger of Allaah (peace and blessings of Allaah be upon him) said, with a group of his Sahaabah standing around him: “Come and give me your oath of allegiance, promising that you will not associate anything in worship with Allaah, or steal, or commit zinaa (illegal sexual activity), or kill your children, or utter slander intentionally forging falsehood (by wrongfully attributing illegitimate children to husbands) [cf 60:12], or disobey me with regard to anything good (ma’roof). Whoever among you fulfils this oath, his reward will be due from Allaah, and whoever commits any of these sins and is punished for it in this world, this will be an expiation for him. Whoever commits any of these sins and Allaah conceals it for him, then his case rests with Allaah – if He wills, He will punish him and if He wills, He will forgive him.” So they gave their oath of allegiance to him on that basis.
Al-Haafiz said in al-Fath (1/6): “What we learn from this hadeeth is that the carrying out of the punishment is an expiation for the sin, even if the one on whom the hadd is carried out does not repent. This is the view of the majority. It was also said that he has to repent – this was stated by some of the Taabi’een.”
The previous hadeeth was also narrated by al-Tirmidhi in his Sunan. After quoting it, he said:
“Al-Shaafa’i said concerning this topic: I have not heard any better indication than this hadeeth to show that the hudood (punishments) are an expiation for the people on whom they are carried out. Al-Shaafa’i said: if a person commits a sin and Allaah conceals it for him, I prefer for him to keep it concealed and to repent, keeping the matter between himself and Allaah. Something similar was narrated from Abu Bakr and ‘Umar, that they commanded a man to conceal his sin.”(Sunan al-Tirmidhi, 1439). So there is no need for the person who commits a punishable sin to go to the Qaadi (judge) and confess and ask for the hadd to be carried out on him; rather, he is encouraged to keep it to himself and to repent, keeping the matter between himself and Allaah, may He be glorified, and to do lots of righteous deeds, for good deeds cancel out bad deeds, and the one who repents from sin is like one who did not sin at all. We ask Allaah to keep us safe and to forgive us. May Allaah bless our Prophet Muhammad.