´It was narrated from Ubadah bin Samit that the Messenger of Allah (ﷺ) said:` “Whoever among you undergoes a Hadd, his punishment has been brought forward, and it is an expiation for him otherwise his case rests with Allah.”
Hadith Referenceسنن ابن ماجه / كتاب الحدود / 2603
Hadith Gradingالألبانی:صحيح | زبیر علی زئی:صحيح مسلم
Benefits and Issues: ➊ If an Islamic punishment is carried out for a crime in this world, then that sin is forgiven.
➋ It is possible that a person is a criminal, but no one becomes aware of his crime, or the crime is not proven against him in court; in such a case, the forgiveness of that person's sin is not certain.
➌ The meaning of the matter being referred to Allah is that it is possible, due to repentance or because of some great good deed, that his sin may be forgiven and thus he is saved from punishment in the Hereafter. And it is also possible that he may have to endure punishment in the grave, or on the Day of Resurrection, or in Hell, and after that he is granted forgiveness.
Source: Commentary on Sunan Ibn Mājah by Mawlānā ‘Atā’ullāh Sājid, Page: 2603