After the resurrection, Jesus entrusted to the Apostles the power to forgive sins: “Receive the Holy Spirit. If you forgive the sins of any, they are forgiven; if you retain the sins of any, they are retained.” (John 20:22-23) This is why we as Catholics go to confession: to use the means that the Son of God has established to guarantee the forgiveness of sins. Only the Catholic Church has the fullness of the means of salvation, and among these are the sacraments. Sacramental confession not only forgives sins (as long as we confess sincerely, are truly repentant, and firmly resolve to amend our lives) but also the grace of God, which is given to us in the sacrament, heals our wounds, self-inflicted by our sins, and it prevents us from falling into new sins.
As far as the question of a protestant who asks forgiveness directly from God—we cannot say with certainty that his sins are forgiven. Everything depends on the intensity of his contrition and his sincere desire to amend his life. Either way, each person will be judged before God according to his level of knowledge of the faith, taking into account whether he has voluntarily rejected the full truth that Jesus has entrusted to the Catholic Church.
A protestant can ask God for forgiveness with a sincere contrition and pure intentions, and actually receive that forgiveness, but he cannot be certain that he has received it. We, however, do have that certainty when we receive the sacrament of confession with a sincere heart.
But a Catholic who knows about the sacraments that Jesus has instituted cannot without fault choose to ignore these channels of grace that God has given us. A Catholic who has received a good formation in the faith has a greater responsibility before God, because “to whom much is given, much will be asked of.” For this reason, someone who has the fullness of truth cannot try to use the extraordinary means of salvation that God uses to save persons who, through no fault of their own, do not have access to the fullness of the means of salvation.
Answer given by Fr. Félix López, S.H.M.