Our sages teach that there is one type of ba’al teshuva (penitent) whose willful sins are turned into merits. ( Yoma 86b)
How does this happen?
If a person sins and then desires to return to God, his sins give him no rest.
They are ever present in his consciousness and continually torment him.
He understands that someone like himself, someone who has sinned and transgressed, is obligated to do much more than others in order to draw near to God.
Thus, the sinners past and sense of loss serve as fuel for doing more and reaching higher.
If a penitent is doubly energized to act as a result of his sins, he is a true penitent – and those sins are transformed into the merits that they inspire.
–Rabbi Adin Steinsaltz