Cardinal Turrecremata says, “Although it clearly follows from the circumstance that the Pope can err at times, and command things which must not be done, that we are not to be simply obedient to him in all things, that does not show that he must not be obeyed by all when his commands are good. To know in what cases he is to be obeyed and in what not … it is said in the Acts of the Apostles, ‘One ought to obey God rather than man:’ therefore, were the Pope to command anything against Holy Scripture, or the articles of faith, or the truth of the Sacraments, or the commands of the natural or divine law, he ought not to be obeyed, but in such commands is to be passed over (despiciendus).”—Summ. de Eccl., pp. 47, 48.
Bellarmine, speaking of resisting the Pope, says, {243} “In order to resist and defend oneself no authority is required … Therefore, as it is lawful to resist the Pope, if he assaulted a man’s person, so it is lawful to resist him, if he assaulted souls, or troubled the state (turbanti rempublicam), and much more if he strove to destroy the Church. It is lawful, I say, to resist him, by not doing what he commands, and hindering the execution of his will.”—De Rom. Pont., ii. 29.
Archbishop Kenrick says, “His power was given for edification, not for destruction. If he uses it from the love of domination (quod absit) scarcely will he meet with obedient populations.”—Theolog. Moral., t. i. p. 158…’
Less explicitly but clearly based on the same principle is the teaching of St Thomas Aquinas on the issue 'Are Subjects bound to obey their superiors in all things? He says "On like manner there are two reasons, for which a subject may not be bound to obey his superior in all things. First on account of the command of a higher power. For as a gloss says on Romans 13:2, “They that resist [Vulgate: ‘He that resisteth’] the power, resist the ordinance of God” (cf. St. Augustine, De Verb. Dom. viii). “If a commissioner issue an order, are you to comply, if it is contrary to the bidding of the proconsul? Again if the proconsul command one thing, and the emperor another, will you hesitate, to disregard the former and serve the latter? Therefore if the emperor commands one thing and God another, you must disregard the former and obey God.” (from the Summa)