SIN may be more beneficial for a person, if it leads him to repent, than doing a lot of worship. This is what an early scholar meant when he said:

“A person may commit a sin and enter Paradise because of it, or he may do an act of worship and enter Hell because of it.”

They asked: “How is that?”

He said: “He may commit a sin and continue to think about it. When he stands, sits or walks, he remembers his sin. He feels ashamed, he repents, seeks forgiveness and regrets it. So that will be the means of his salvation.(As for the other person), he may do a good deed and continue to think about it. When he stands, sits or walks he remembers it and it fills him with self-admiration and pride, so it becomes the cause of his doom.”

So a sin could be the factor that leads him to do acts of worship, good deeds and change his attitude. This is better for a person than an act of worship that makes him proud and he looks down on people. Undoubtedly this sin is better before Allah and is more likely to bring salvation than one who admires himself. Even if his words indicate something else, Allah is the Witness over what is in his heart.

– Madarij as-Salikeen, 1/299