The Prophet ﷺ has said: “Hearing and obeying is an obligation of every Muslim, whether he likes the command or dislikes it, as long as he is not commanded to commit a sin. If he is commanded to commit a sin, then he absolved of the obligation to hear and obey.” [Sahih Muslim].
(I say): Since an imām is installed for two kinds of public weal, by which religious and political affairs are regulated, and since the Prophet ﷺ was sent for their sake, and the imām is the Prophet’s deputy and an executor of his mission, therefore, obedience to the imām is indeed obedience to the Prophet ﷺ. And disobedience to him would be tantamount to disobedience of the Prophet ﷺ except when he commands to commit a sin. For then it would be evident that obedience to him is not longer an obedience to God, and in that event, he would cease to be a deputy of God’s Prophet ﷺ. This is why the Prophet ﷺ said: “Whoever follow an amīr, he indeed follows me, and whoever disobeys an amīr, he indeed disobeys me”. [Sahih Muslim]
Further, the Prophet ﷺ has said: “Verily the imām is a shield behind which his people fight their enemies, and through which they seek their own protection. If he commands piety and guides them toward it, he shall be entitled to a reward for it. But if he pursues any other path, then he shall have his portion of the evil consequences.” [Sahih Muslim]
(I say): The Prophet ﷺ regarded the imām as a shield because he is an instrument of inner cohesion among Muslims and a source of defence for them. The Prophet ﷺ has also said: “Whoever finds something in his amīr which he detests, he should tolerate it, because whoever separates himself a single span of hand from the community and dies in that position his death shall indeed be in the state of Jāhiliyyah”. [Sahih Muslim]
(I say): This is because Islam is distinguished from Jāhiliyyah by addressing these two categories of public weal. And it is the khalīfah who deputises the Prophet ﷺ in carrying out the purposes of this public weal. Therefore, when someone separates himself from the executor of this public weal, he falls in the category of those who are living in the Jāhilī era.
The Prophet ﷺ also said: “Any servant of God to whose care God gave a people, but he did not lend his fullest sincerity to their cause, he shall not [even] smell the fragrance of paradise”. [Bukhari]
(I say): Since the installation of [the] khalīfah takes place for the realisation of certain vital interests, it is necessary that the khalīfah is directed to fulfil these objectives. At the same time, the people should also be urged to follow him so that these stipulated interests are achieved from both sides.
[Shāh Walī Allāh, Selection from Hujjat Allah al-Balighah, English Translation by Muhammad al-Ghazali, Adam Publishers, New Delhi, 2006, pp. 116-117]