well think about it this way, lets say you’re playing ball outside, and you accidentally break a neighbors window with the ball, well even though you apologize and they forgive you for it, you still have to pay for the broken window…that’s how it is with sin, even though God forgives you when you go to confession, you still have to pay for what you’ve done,
or here’s another way to look at it,
lets say you’re going to a birthday party, and you’re wearing a pretty white dress, but on your way there you fall in a mud puddle, now would you still go to the party with your dress stained like that? of course not, you’d want to go home and get the stain out(or change your clothes, but that ruins the point :B )
that’s how it is when you die, and your soul is stained with sin, you don’t *want *to go to heaven like that, you would insist on going to purgatory first.
although there are also indulgences, which do remove the stain of sin, you can read up on indulgences here -
catholicapologetics.info/thechurch/encyclicals/indulg.htm
or if you don’t want to read all of that, you can also ask your priest about indulgences.