In addressing this question, we must first remember that the Sacrament of Holy Orders, like Baptism and Confirmation, is a character sacrament. Each character sacrament confers an indelible spiritual character upon the recipient. These sacraments are not repeated and are not temporary. The spiritual character cannot be lost due to mortal sin, even though the state of sanctifying grace can. (Please note that in the case of Holy Orders, the man receives the sacrament in three degrees – diaconate (deacon), presbyterate (priest), and episcopate (bishop), which alone confers the fullness of the character of the sacrament.)
For example, suppose a baptized Catholic decided to leave the Church, renounce the faith, and become a Moslem. Twenty years later, he decided to return to the Catholic Church. This person would not be re-baptized or re-confirmed because the character of the Sacraments of Baptism and Confirmation remains. Instead, he would make a good confession and receive absolution, and then make a Profession of Faith. (See Catechism, #1581-2.)
Therefore, when a man is ordained as a priest, he receives this sacred character to act in the person of Christ and as His instrument for His Church. He also receives faculties from the Bishop of the Diocese or other legitimate authority to perform his ministry.
So what happens when a priest leaves the priesthood? Since Holy Orders is a character sacrament, once it has been validly received, it never is invalidated for any reason whatsoever. Granted, a cleric– deacon, priest, or bishop– may be freed from the clerical state and dispensed from the promise of celibacy by the proper authority. He may no longer have the obligations or the privileges to function as a cleric, but nevertheless he remains a cleric. Commonly, this practice is called laicization, meaning “returned to the state of the laity.” (Code of Canon Law, #290-293.)
Even though the cleric has been laicized and no longer functions as a deacon, priest, or bishop, he still has the sacramental character of Holy Orders. Technically, if he were to perform a sacrament in accord with the norms of the Church, that sacrament would indeed be valid. However, the sacrament would be illicit, meaning he violated Church law and would be culpable for this infraction since he no longer has the faculties to function as a priest.
The Code of Canon Law makes one exception for emergency circumstances: “Even though he lacks the faculty to hear confession, any priest validly and licitly absolves from any kind of censures and sins any penitent who is in danger of death, even if an approved priest is present” (#976). Here the Church is recognizing the indelible spiritual character received by the priest– although now laicized– at his ordination.
For instance, suppose a person was hurt in a car accident and was dying. No priest could be found to hear the person’s confession. A laicized priest– maybe having not functioned as a priest for years– could licitly hear a dying person’s confession and validly absolve him from all sin. Moreover, even if this priest had left the priesthood without proper permission and was in a state of mortal sin, he could still validly absolve the dying person of sin.
Keep in mind too that if a laicized priest decides to return to the active ministry, he would not be re-ordained. Instead, he would have to have permission from the Holy Father and complete whatever other requirements the bishop or other Church authority would impose. (See Code of Canon Law, #293.)
(Please note that even if a priest leaves the active ministry without proper permission and without ever being laicized, he too still has the sacramental character of Holy Orders. He too could validly absolve sins in an emergency situation.)
While this answer addressed a technical question concerning the validity of sacraments, it also dealt with a painful subject– priests who have left the priesthood. All Catholics should pray particularly for their parish priests who labor to do the Lord’s work and that by God’s grace they will reflect the person of Christ in whose name they act in performing the sacraments. We too should pray for those priests who have left the active ministry, that if possible, they will return to the vocation to which they were called and exercise the great gift of priesthood they have received.