It is desirable not to reveal such sins to others.
The Holy Prophet (sws) would not willingly hear such voluntary confessions. If
someone questions such a person he should try not to reveal the matter. However,
if the matter has been brought before the court and he is questioned there, then
he is not allowed to hide the truth.
The Prophet (sws) is reported to have said:
He among you who gets involved in such filth, should
hide behind the veil stretched out for him by Allah, but if he unfolds the veil,
we shall implement the law of Allah upon him. (Mu’atta: No. 1562)
Similarly, he once told a person:
If you had hidden the crime of this [person], it would
have been better for you. (Mu’atta: No. 1553)