All perfect praise be to Allah, The Lord of the Worlds. I testify that there is none worthy of worship except Allah, and that Muhammad is His slave and Messenger.
The situation in which a person is permitted to tell about the sins he had committed is when there is a significant benefit that would be achieved as a result of disclosing them, whether the person committed the sin while unaware of its ruling or knowing it; what matters is whether or not there is a benefit to be achieved.
If there is a benefit which is predominantly expected to be achieved (by disclosing one's sins), such as when seeking a Fatwa (Islamic jurisprudential verdict) from a scholar on how to repent, or when admonishing a person hoping that he will be deterred (from committing the same sins), and the like, then in such cases informing about the sin is not dispraised.
Faydh Al-Qadeer reads:
"An-Nawawi said: ‘It is disliked for the one who committed a sin to tell others about it. Rather, he should refrain and regret having done it, and be determined not to return to it again. If he tells his Shaykh about it, or any other person who may teach him the way out of it, or how to be safe from falling into similar sins again, or inform him about the reason that led him to fall into it, or so that he would supplicate for him (to be forgiven) and the like, then this is fine. It is only disliked when there is no benefit to be achieved (by disclosing them).’
Al-Ghazaali said: ‘Disclosing sins is dispraised when it is done as a way of publicizing sins or to mock (the religion), and not when one is asking and seeking a Fatwa. The evidence substantiating this is the narration of the man who had sexual intercourse with his wife during daytime in Ramadan. He went to the Prophet and informed him about it, but the Prophet did not object to him disclosing his sin.’” [End of quote]
Allah knows best.