Imam Ghazali on the ‘Ulamā’ of the Hereafter, the Teachers of Falsehood and Avoiding Rulers

“Another characteristic expected of the scholar is that he keeps away from the rulers and, as long as he can help it, not to come near them at all, and rather avoid their company despite any efforts on their part to seek him out, because the world is attractive and inviting while the power to dispense with its riches is in their hands. To associate with them, therefore, would necessarily involve the scholar in seeking their approval and winning their hearts, although they are unjust and unrighteous. It is, then, the duty of every religious man to censor them by exposing their tyranny and decrying their practices. For he who frequents their palaces will either seek their favour and consequently forget the blessings which Allah has bestowed upon him, or hold his peace and allow their misdeeds to go uncensored, thereby courting their favour.”

Imam Qurtubi: Knowledge of Obedience to the Caliph is like Knowledge of Prayers and Fasting

"and that would be part of the dīn of Allah which is obliged for him, just as every responsible person knows from the dīn of Allah what is obliged for him regarding the five prayers, fasting Ramadan, ḥajj and the like"