well, confession is properly called the sacrament of penance, sacrament meaning a sensible sign instituted by Jesus Christ as a physical means to obtain invisible grace and inward sanctification, in which case there needs to be a physical means of obtaining the spiritual,
and then penance meaning to make reparation for, which is what we do in confession, which i will explain how -
first of all confession is an act of humility, when you go you are humbling yourself, saying “I am a sinner Lord, forgive me” and by that you make reparation(if it is sincere), because it is not always an easy thing to do, and also because you are not just saying “i am sorry”, you are proving it, it’s easy enough to just say you are sorry, but to humble yourself like that and do something you don’t really want to do is really saying “see Lord, i am truly sorry”…that is something you need to prove to yourself as well.
and then also it is an act of reparation because of contrition, when we go to confession we must move ourselves to have true sorrow for offending God,
and at the end of your confession the priest gives you a penance to do, whether it is a prayer, or some good work, or to repair some damage you have done, or whatever he sees fitting,
we are told that confession is for those who have been baptized to be able to receive sanctifying grace again in their souls, but why is that? why can’t the unbaptized go to confession? because confession is not just for forgiveness,
when we are baptized we receive sanctifying grace for the first time, baptism is also a sacrament, it is a physical means of obtaining extraordinary grace(sanctifying grace)
but you can only receive baptism once, because it is a permanent mark on your soul which can not be added on to or taken away,
so when you lose your sanctifying grace by committing a mortal sin, how do you get it back? just as you needed a physical sign to get it in the first place, you need it again to get it again,
you need a sacrament to receive sanctifying grace, which is of course the sacrament of penance,
so the reason the unbaptized don’t go to confession is because confession is for getting sanctifying grace back, which can only be obtained by a sacrament.
Jesus wanted it this was for many reasons, and one good reason is simply because you cannot trust in anything else, Jesus Himself instituted confession, and we know that God is all fair, so when you go to confession, and are sincere and truly sorry, then you can be assured that you will receive your sanctifying grace back again, because Jesus said so.
but you cannot have that kind of assurance by doing something which God has not told you to do, we have never been told to “just confess to God” for forgiveness, and why not? well it would be kinda silly, God already knows your sins, He doesn’t need to hear them, the priest needs to because He is the one who must decide if you can be absolved or not, and then he is the one who will give you a penance based on your sins,
of course you are really confessing to Jesus in the confessional, but you need a physical sign and a verbal communication, we are physical being, our bodies are dominant over our souls, and so Jesus has made things work accordingly,
well i think i over explained things…but i hope this helps you, if you have anymore questions, please ask.