Q. If a priest in a state of mortal sin celebrates Mass or provides other sacraments, are they still valid?
A. Yes, they are valid, as long as the minister of the sacrament intends to do what the Church intends. The theological principle at work here is ex opere operato, explained in the Catechism of the Catholic Church this way:
“The sacraments act ex opere operato(literally: ‘by the very fact of the action’s being performed’). … It follows that ‘the sacrament is not wrought by the righteousness of either the celebrant or the recipient, but by the power of God.’ From the moment that a sacrament is celebrated in accordance with the intention of the Church, the power of Christ and His Spirit acts in and through it, independently of the personal holiness of the minister” (no. 1128).
Nevertheless, the personal holiness and piety of the priest can have a huge impact on the lives of the faithful he serves. For that reason priests are encouraged to celebrate the holy sacrifice of the Mass daily, go to confession regularly, and pray frequently.