I’m going to borrow a statement from Fr. Serpa, which I read in the AAA forum: we’re not dealing with magic here.
A properly ordained priest has the ability to confer sacraments. If he is in a state of moral sin, he still has that ability, by virtue of his office, though I expect he is sinning further if he confers the sacraments. His sin does not affect other people, and it certainly does not have the ability to impact wheher or not Christ is present in the Eucharist or whether sanctifying grace is received by some he baptises, or whether the absolution he grants in confession is valid.
If the priest’s intent is to perform the sacrament, it’s performed. If he is secretly in league with Satan and seeks to defile the Eucharist, that may be a different story, but that’s not what the OP is asking.
The idea of the priest’s sin being contagious is odd, too. Have you a source for that?