All perfect praise be to Allaah, The Lord of the Worlds. I testify that there is none worthy of worship except Allaah, and that Muhammad is His slave and Messenger.
The scholars are of the view that it is desirable for a person who has committed a sin that necessitates a Hadd (i.e. the corporal punishment determined by the Islamic Law) to conceal his sin and not confess it (to the authorities) so that the Hadd would be implemented on him. The evidence which they provided for this view is the saying of the Prophet : "Whoever happens to commit any of these filthy things, should conceal himself with the screen of Allaah, and repent to Him, because whoever discloses to us what he committed, we will apply the Rule of Allaah (i.e. the Hadd) on him." [Maalik in Al-Muwatt’a and Al-Bayhaqi in As-Sunan]
Besides, Ibn Hajar stated that some scholars found a discrepancy between the desirability of concealing one’s self and the fact that Maa’ith and Al-Ghaamidiyyah were praised for confessing their guilt to the Prophet . Then he (Ibn Hajar) conveyed the answer of his Shaykh, i.e. Al-Iraaqi in his interpretation of At-Tirmithi, that Al-Ghaamidiyyah became pregnant without being married and thus it was impossible for her to conceal her sin of Zina (fornication or adultery) because it was easy to see the result of her Zina. So, some scholars stated that it is preferable to conceal one's sin on the condition that there is nothing to prove the opposite (i.e. when it is not possible to know the sin), otherwise it is better to go to the Muslim ruler so that he would implement the Hadd on the person.
This is what Al-Iraaqi mentioned in this regard, then Ibn Hajar mentioned his statement commenting on Al-Iraaqi’s explanation – we mean Ibn Hajar’s statement: concealing one’s self is desirable but confessing one’s sin (to the Muslim ruler) to be absolutely purified from one’s sin is more desirable.
This is what Ibn Hajar concluded as a way of reconciling between the story of Maa’ith and Al-Ghaamidiyyah and what is established (in the Sunnah) that concealing one’s sin is desirable. Such conclusion indicates that (in this case) one's taking the matter to the Muslim ruler to be absolutely purified from the sin is better than concealing his sin.
Finally, it is known that confessing one’s sin (in front of the ruler) so that the Hadd would be implemented on him should be done when the Sharee’ah of Allaah is applied, otherwise concealing one’s sin is better, as there is no benefit of confessing one’s sin in this case.
Allaah Knows best.