Answer:To explain the relationship of grace to sacramental Confession we need to look first at the nature of grace, and the role of grace in Baptism. Here is how Donald Attwater’s A Catholic Dictionary defines “grace” and “sanctifying (habitual) grace”:
(Lat. gratia, favour). i. Strictly, a supernatural (q.v.) gift of God to an intellectual creature, bestowed with a view to eternal life. In 1713, in the bull Unigenitus, Pope Clement XI condemned the Jansenist proposition that “no grace is given outside the Church.”1
GRACE, HABITUAL. An absolutely supernatural (q.v.) quality, intrinsically and permanently inhering in the soul, by which we are made friends of God, adopted sons, co-heirs with Christ, “partakers of the divine nature” (q.v.). It is a created and finite habit, not to be identified with the Holy Ghost indwelling in the souls of the just; fixed in the soul it is no mere imputation of the merits of Christ, no mere “garment” (the Protestant error). When Scripture so speaks of it, it is merely to indicate that it has an external origin in the merits of Christ.
Of importance in these definitions are the ideas that grace is something supernatural; something on God’s level rather than our own-and that it makes its recipient somehow fit for the life of eternity with God. We can say that it raises up created beings like men and angels from their natural state, to a state of sharing something of God’s divine nature and life. (It is not, as some modernists hold, the changing of man into God or a god.)
When God created Adam and Eve, in addition to their natural body and soul, and certain preternatural gifts that kept them from pain and toil, he gave them supernatural graces which raised them to a state of direct communication and friendship with Him. To use the term employed by Saint Paul in his Epistle to the Romans, we can say that in this state of original grace Adam and Eve were “justified”-which is to say that as children of God, the good works they did would have earned them heavenly merit. Their state of “justification is sometimes called “original justice.” Had they not sinned, these graces would have been passed on to their descendents through natural generation. Since they did sin, however, they lost this grace, and, therefore, were not able to pass it on to their children.
We say that children born without this grace are in the state of “original sin”-although it would probably be less confusing to say that that had not inherited “original justice” or grace. Like the child born to a wealthy father who gambled away all his money, the child is not at fault, but he is still without an inheritance. We children of Adam are born without the grace that Adam possessed in such abundance, and of ourselves, we are utterly powerless to bridge the chasm that now exists between God and fallen human nature.
After Adam’s loss, God promised to send a Redeemer, born to a woman who would crush the serpent (who represented sin and the devil).2 By a special act of the divine will, the Blessed Virgin Mary was conceived in the state of grace, and later miraculously conceived and gave birth to the Son of God. As God and man, Jesus Christ was uniquely capable of redeeming man from sin, restoring him to grace, and bridging the gulf between the natural and the supernatural. As man-a “second Adam”-He could represent the human race before God. As God, the Son of God, the offering of His life, death, and resurrection on our behalf was infinitely pleasing and meritorious in God’s sight.
The Redemption of mankind made it possible for individuals to receive sanctifying grace, so that by doing good they might merit the reward of heaven-but not all men will accept and cooperate with this grace-all men are redeemed, but some may not be saved. “To those who believe in Jesus Christ, He gave the power of becoming sons of God.”3 “He who believes and is baptized will be saved, but he who does not believe shall be condemned.”4
. Actual grace enlightens the mind and frees the will with a view to the work of salvation. In this stirring of the will there are two moments: the first of which is a grace which moves the will spontaneously, unfreely, making it incline to God, and this is a “prevenient grace.” The heavenly inspirations may be accepted freely, or rejected freely by the aroused will. If they are accepted it is in virtue of a further grace (or the same grace under a different aspect) which is called “consequent” or “co-operating grace.”
“Prevenient” simply means “coming before,” and it is “prevenient grace” with which God offers a sort of invitation to investigate and accept the truths of revelation that He has entrusted to his Church. Such grace is given freely to the unbaptized person, who may freely choose to accept or reject it. The effort to become familiar with the truths of the Faith is the occasion of “co-operating grace.” The firm decision and desire to receive Baptism and conform to the teaching of the Church is the occasion of “justification of the sinner ... a translation ... to the state of grace and of the adoption of the sons of God....”5 Normally, unless the person is seriously ill, Baptism is received at the time appointed by the Church-and must be received before the person can progress to any of the other Sacraments. It is the general teaching of the Church that the life of one awaiting Baptism under these circumstances, if unexpectedly cut short by accident or martyrdom, but still in the grace of justification, will end in the happiness of heaven.6
All of the Sacraments effect what they symbolize-so in the case of the adult convert or even in the case of an infant or an intellectually incapable person, with sacramental Baptism sanctifying grace brings an infusion of faith, hope and charity, and the soul is permanently marked with the “character” of a Christian in order that it may benefit from the other Sacraments. Baptism wipes away all sin and the penalties associated with it. With regard to grace, we can say that Baptism raises the soul to participate in the divine life. Baptism is sometimes called a “Sacrament of the Dead,” in that it raises a figuratively dead soul to life with God.
In most cases, Baptism is received early in life, and a number of years pass before death and judgment. For this reason our Lord also instituted the Sacrament of Penance, giving His priests the power to forgive or “retain” (not forgive) the sins of Christians committed after Baptism.7 That the priest is to make this decision indicates that sins must normally be confessed before they can be absolved.
From the perspective of grace, Penance is much like Baptism. A person who has forfeited the life of grace, like one who did not receive it from his parents because of original sin, makes a conscious decision to amend his life because he is sorry for having offended God whom he loves. If his motive for contrition is truly based on the love of God-“perfect contrition”-grace is immediately operative.8 Even the fear of hell is an adequate motive for sacramental Confession, and, in any event, the sinner must normally receive sacramental absolution before receiving any of the other Sacraments.
In both cases, that of Baptism and that of Penance, a soul that is functioning without a part in the supernatural life of God is raised to a share in that life. The fallen children of Adam and Eve become the adopted sons of God “through the Second Adam, Jesus Christ, our Savior.”
 Genesis iii: 15.
 Cf. John i: 11-13.
 Mark xvi: 16.
 Council of Trent, Decree on Justification, Session VI, 3 January 1547, Chapter IV (Denzinger 796/1524).Cited in "anathema" form by Session VII, 3 March 1547, Canon 4 (Denzinger 847/1604).
 1917 Code of Canon Law, canon 737 §1, Roman Ritual, Part II, Chapter I, para #1.
 John xx: 19-23.
 Council of Trent, ibid., Session VI, Chapter XIV