That’s correct. But an excommunication can be objectively unjust and invalid.
The Church is a society, an ordered whole engaged in a shared activity. This activity is the essential unity of the Church: it’s the profession of Faith. The role of the Holy Father is principally to make manifest the object of our Faith. He guarantees the unity of the Church chiefly by making manifest the object of our Faith, by formulating the Creed or Symbol.
This is what St. Thomas Aquinas explains in the Summa (II-II, Q.1, art. 10):
I answer that, as stated above (Objection 1), a new edition of the symbol becomes necessary in order to set aside the errors that may arise. Consequently to publish a new edition of the symbol belongs to that authority which is empowered to decide matters of faith finally, so that they may be held by all with unshaken faith. Now this belongs to the authority of the Sovereign Pontiff, “to whom the more important and more difficult questions that arise in the Church are referred,” as stated in the Decretals [Dist. xvii, Can. 5. Hence our Lord said to Peter whom he made Sovereign Pontiff (Luke 22:32): “I have prayed for thee,” Peter, “that thy faith fail not, and thou, being once converted, confirm thy brethren.” The reason of this is that there should be but one faith of the whole Church, according to 1 Corinthians 1:10: “That you all speak the same thing, and that there be no schisms among you”: and this could not be secured unless any question of faith that may arise be decided by him who presides over the whole Church, so that the whole Church may hold firmly to his decision. Consequently it belongs to the sole authority of the Sovereign Pontiff to publish a new edition of the symbol, as do all other matters which concern the whole Church, such as to convoke a general council and so forth.
But what are Catholics to do when the Monarch of the Church no longer fulfills his role? When he teaches a different doctrine? All they can do is hold on to the Faith, and do whatever is in their power to continue in that same Faith.
I do re-evaluate. Constantly. As best I can.
Catholic obedience and Faith is not a blind one. We will be held responsible if we obey commands we should have known were evil.