While God can and does offer forgiveness for sins of those who have perfect contrition outside of the sacrament, He gave us the sacrament for several reasons. One as assurance that we are forgiven, secondly because many if not most people do not have perfect contrition, but rather attrition, which is sorrow for our sins because we fear the punishment for sin.
The seven Sacraments are the greatest source of grace, however when we are in a state of grace, (no stain of Mortal sin in our soul) then we can obtain graces through wuch means as prayer, (formal like the rosary, or a prayer of our own composition) charitable works, (feeding the hungry, instructing those who need assistance, etc, done for the glorification of God) The key is to not impose a barrier to the reception of grace, by being in a state of grace, and we do that most successfully by frequenting the sacraments, most of all confession and the eucharist. They strengthen our resolve and our spiritual growth.
Many people will eat well, and go to the gym, avoid cigarettes and excessive alcohol to strenghten their bodies. However they forget that in order to have a strong and fit soul, they also need to exercise it. By frequesnt reception of the Eucharist, confession and spiritual practices we exercise our soul, and become more fit as Christians. Because many people did not think of their souls, and neglected to nourish them, the Church imposed legislation that (Latin Rite) Catholics go to confession and receive communion at least once a year, (during Eastertide) and attend Mass on Sundays and Holy Days of Obligation.