Can an excommunicated priest still change bread and wine into the body and blood of Christ?
St. Thomas Aquinas explained this in his work Summa Theologica (III, Q82):
Article 7. Whether heretics, schismatics, and excommunicated persons can consecrate?
I answer that some have contended that heretics, schismatics, and the excommunicate, who are outside the pale of the Church, cannot perform this sacrament. But herein they are deceived, because, as Augustine says (Contra Parmen. ii), “it is one thing to lack something utterly, and another to have it improperly”; and in like fashion, “it is one thing not to bestow, and quite another to bestow, but not rightly.” Accordingly, such as, being within the Church, received the power of consecrating the Eucharist through being ordained to the priesthood, have such power rightly indeed; but they use it improperly if afterwards they be separated from the Church by heresy, schism, or excommunication. But such as are ordained while separated from the Church, have neither the power rightly, nor do they use it rightly. But that in both cases they have the power is clear from what Augustine says (Contra Parmen. ii), that when they return to the unity of the Church, they are not re-ordained but are received in their orders. And since the consecration of the Eucharist is an act which follows the power of order, such persons as are separated from the Church by heresy, schism, or excommunication can indeed consecrate the Eucharist, which on being consecrated by them contains Christ’s true body and blood; but they act wrongly, and sin by doing so; and in consequence they do not receive the fruit of the sacrifice, which is a spiritual sacrifice.