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.
That person is not obliged to confess the insult that he made in secret to the judge as long as he has sincerely repented to Allaah of that sin. The fact that a sin entails the application of a hadd (i.e. corporal punishment) does not mean that the doer is obliged to report his sin to the concerned authorities; rather, he should not disclose his sin to anyone, but keenly repent to Allaah of his sin and strive in carrying out righteous deeds that would erase his sin. The Prophet said, "One who repents from sin is like one without sin." [Ibn Maajah] He also said, "O People! The time has come for you to observe the limits of Allaah. Whoever has had any of these ugly evils befall him should cover them up with the veil of Allaah. Whoever reveals his sin to us, we (are obliged to) apply what is in the Book of Allaah against him (prescribed punishment)." [Maalik: Al-Muwatta’]
For more benefit, please refer to fataawa 83573, 87700 and 83416.
The fact that obedience to the ruler is obligatory is irrelevant in this regard; there is no such ruler who commands his subjects who have committed sins punishable by a hadd or committed apostasy to report them to him (so as to receive his due punishment)!
Allaah knows best.