Christ is not free to indwell the sinful priest until the sinful priest returns to God, confesses his sins, known and unknown, and then resides in fellowship with God the Holy Spirit, who provides the temple for the indwelling of Christ.
So the question remains regarding the ability of a sinful priest who isn’t in fellowship to forgive the sins of others.
WRT the Protestant denominations, they don’t pretend the pastor-teacher has a role as confessor, but instead recognize the royal family provided by God for each and every believer as a priest to God the Father, through the High Priest, Christ Jesus.
First off, how would you know if the priest is in a state of sin?
Assuming he was (since you can't determine it), the validity of the Sacrament does not depend upon the holiness of the minister. As long as the matter and form are correctly used, that is, the sign is correctly placed as Christ instituted it, by someone who is empowered to place that sign, and as long as the correct intention, to do as Christ or the Church desires, is present, the Sacrament is valid. However, a priest who would administer a Sacrament while being personally in a state of mortal sin, would himself be committing an additional mortal sin of sacrilege.
Which now raises another question: "What constitutes a mortal sin?"
Question for you! What does WRT signify?