How can a sin that has been retained by a priest in confession be forgiven?
By "retained in confession" I assume you mean that the priest confessor did not give absolution to the penitent for his or her sin. This would be because the confessor judged that the penitent confessing was not sufficiently contrite for the sin committed, usually because he or she lacked the purpose of amendment, that is, was not willing to give up the sin or its near occasion.
Denying absolution is rather rare, since usually, even if the penitent is weak and frequently falls back into sin, at the time of confession he or she is willing to keep on trying, making use of the means of grace and the advice of the confessor. If the confessor perceives that this is lacking, he might refuse absolution, or "retain" the sins confessed. The penitent should use this as a helpful experience and pray for the grace of a true purpose of amendment and real contrition so as to be absolved.
Of course, there can be a misunderstanding or the priest could be being unreasonable (though this is rare!), and so the penitent is free to go to another priest and confess again, explaining that he has been refused absolution and that he is still seeking it. The new confessor should listen carefully and evaluate what he hears. He may agree with the first confessor, but if he does not, he is free to absolve the penitent, even if the penitent was refused by another priest.