There are basically two different "economies" at work here, a natural economy and a supernatural economy.
Natural Economy: When I do bad, God punishes the bad. When I do good, God rewards the good.
Supernatural Economy: Completely unmerited, a free gift of God, which cannot be earned by the Natural Economy (above).
There is some interplay here, though, namely that, when I do something (very) bad, I lose the supernatural grace, but on the flip side, there's nothing good I can do to gain that back. It has to be restored by a free gift of God, though the Sacraments. I cooperate of course by going to the Sacrament, but that itself doesn't earn the grace of God back.
On top of that, if someone is in the state of grace, whatever good they do also has supernatural merit, but that's only a function of the fact that it is God acting through us who is earning the merit for us. If I am not in a state of grace, the natural good that I do has no supernatural merit.
But I hold that it is possible to offset the natural punishment due to sin by good works.
Let's say I am in a state of grace, and I steal $100 from a poor person (a mortal sin). I lose the grace of God. But then I immediately regret it and return the $100, and then give them an additional $50 for good measure. Returning the money doesn't restore me to the grace of God, because that's a different economy, but it does offset the punishment due to the theft.
Let's say I am in a state of grace, and I steal $100 from a poor person (a moral sin). I lose the grace of God. I go to Confession and am restored to grace. I still need to make good on the $100 I stole from the person, and until I do so, I am owed punishment for that despite having the guilt of sin remitted.
Let's say I am not a Catholic. I steal the same $100. I return the $100 and give an extra $50 to make up for it. Would I be punished for this in eternity the exact same way that a person who stole $100 and failed to pay restitution? That would be not be right in the natural economy of justice. Neither one of these people who the guilt of sin remitted since there's no remission of sin outside the Church, but their punishment in eternity will be quite different.