Is it permissible for a person to disclose a sin which he has performed in a seclusion to a therapist to get rid of that sin for example masturbation

Yes, as long as it is for the purpose of treatment and does not result in loss of dignity