I got a pretty good answer via PM from an anonymous user without an account on here and thought it was worth sharing:
but there's actually an answer to it in church doctrine.
1. The Catholic church does consider the office of a priest and the sacrament of priesthood two different things.
2. While the office of priest, like any other church office, can be given and retracted by church authorities at any time and is subject to the church's internal rulings, the sacrament of priesthood is considered indelible - once you have made the vows and have been consecrated and ordained as a priest, earthly powers can't remove this from you, ever.
3. To solve this conundrum, the church has built a workaround: if you are removed from the office of priest, you are usually prohibited from practicing as priest under pain of excommunication - i.e. they recognize that you still have the sacrament of priesthood, but forbid you from using it. This is what happens to Priests that are convicted of e.g. abuse, or openly live in situations that are contrary to church rules, e.g. are married, openly non-celibate or sth. like that.
4. In practice that means that sacraments these priests give out are considered valid, but they're technically forbidden to do so. There are exceptions, for example for cases where the shunned priest is the only priest available to give last rites to a person that is dying, or to baptize a stillborn baby etc. where that ban is temporarily lifted or not considered broken.
The technical term for all of this is Defrocking:
en.wikipedia.org/wiki/Defrocking , the specifically Catholic version is called Laicization:
en.wikipedia.org/wiki/Loss_of_clerical_stateWhile i am not currently aware of any case where this was used against a transgender person, i'm sure that some variant of this general procedure would be followed if such a case arose, as it has been used in the recent past for cases where priests and other officeholders went against church doctrine. In the case that a person outs themself as transgender before receiving the sacrament of priesthood, the church considers it a mental illness in any case, and thus bars people from not only becoming priests, but also from getting married:
www.katholisch.de/artikel/29274-kirchenrechtler-nur-ein-bedauerndes-achselzucken-fuer-transsexuelle / Source in german, author is a professor of canonic law at the church-sponsored concordat chair of canonical law at Freiburg university, the relevant excerpt is:
Frage: Warum gerade diese beiden Sakramente – und die anderen nicht?
Bier: Weil nur bei Ehe und Priesterweihe das Geschlecht entscheidend ist. Die Ehe ist nach kirchlichem Verständnis ausschließlich eine Gemeinschaft von einem Mann und einer Frau – da braucht man eine eindeutige Zuordnung. Das andere Sakrament ist die Weihe, weil die nur ein getaufter Mann gültig empfangen kann. Wer vom Genotyp her kein Mann ist, kann nicht geweiht werden – und wer zwar genetisch ein Mann ist, aber als Frau lebt, dem wird diese Unsicherheit in der Geschlechtsidentität als Weihehindernis ausgelegt. Bei den anderen Sakramenten ist das egal. Da ist immer nur von Gläubigen die Rede, das ist nicht geschlechtsspezifisch festgelegt. Daher können die anderen Sakramente gespendet werden.
Question: Why just these two sacraments`?
Bier: The question of Gender/Sex is only relevant for Marriage and Priesthood. Marriage is, according to church teachings, exclusively an union between a man and a woman - you need an unambiguous situation. The other sacrament is a consecration that's only validly accessible to baptized men. People that are not genotypically men can not become consecrated, and people that are genetically male but live as women are considered mentally unstable and thus barred from the sacrament. For other sacraments this does not matter because they're accessible to all believers, Sex/Gender does not matter there. So these sacraments can be freely given.
Frage: Wenn eine Trans-Frau eine Frau heiraten will, würde das vom Genotyp her ja passen – aber das würde die Kirche doch wahrscheinlich trotzdem nicht machen?
Bier: Richtig. Der Umstand, dass jemand sich seinem genotypisch vorgegebenen Geschlecht nicht zugehörig fühlt, würde – ähnlich wie bei der Weihe – als Persönlichkeitsstörung gedeutet, die als Eheunfähigkeit ausgelegt würde. Damit pathologisiert man natürlich den Sachverhalt. Ansonsten wäre immer noch ein Argument, dass aus dieser Verbindung keine Kinder hervorgehen würden. Das hängt immer von der Art der Umwandlung ab, aber letztendlich würde man sich auf eines dieser Argumente zurückziehen. Damit muss man sich der eigentlichen Frage nach der Geschlechtlichkeit nicht mehr stellen.
Q: If a Trans-Woman wants to marry a woman, that would be match from a genotype point of view - but the church would not stand for it, right?
Bier: Right. The fact that someone does not accept their birth Sex/Gender would - just like it is the case for Priesthood - be considered a mental affliction that directly leads to unfitness for marriage. This, of course, pathologizes the situation. Another argument would be that no children could result from such an union. Depending on the mode of gender transition, church doctrine would retreat to one of these arguments. Thus, it does not need to face the actual question of Sex/Gender.
Do note that German does not have different words for Sex and Gender, both are unfortunately called 'Geschlecht'
So, to recap, under current church teachings, a transgender person would be considered unfit to become a priest if they outed themselves before getting consecrated. After becoming consecrated, the sacrament of priesthood can not be taken from them, but they could be forbidden from 'practicing' under pain of excommunication, barring extreme circumstances where they'd be the only source of a sacrament of prime importance.