The first category is whatever Allah has commanded; obedience to the rulers in such matters is obligatory for two reasons: because Allah has ordered it and because they have ordered it.
The second category is whatever Allah has forbidden; here it is not permissible to listen to them or obey them, even if they give the command.
The third category covers matters about which Allah has issued neither a command nor a prohibition. In these we are required to obey them, for the Messenger of Allah, peace and blessings be upon him, only barred obedience when they order disobedience.
We ask Allah to set all of us right—subjects and rulers alike—and to grant us mercy from Him. Indeed, He is the Ever-Bestower.
6/668 – ‘Abd Allah ibn ‘Amr, may Allah be pleased with him, said: “We were with the Messenger of Allah, peace and blessings be upon him, on a journey. When we halted, some of us set about pitching their tents, some practised archery, and others tended their grazing animals. Then the caller of the Messenger of Allah announced, ‘The congregational prayer!’ so we gathered around the Messenger of Allah. He said: ‘There has never been a prophet before me except that it was incumbent upon him to guide his community to whatever good he knew for them and to warn them against whatever evil he knew for them. The well-being of this nation has been placed at its beginning, and its latter part will be afflicted with tribulation and matters you will disapprove of. Trials will come, each making the one before it seem light; a trial will come and the believer will say, “This is my ruin,” then it will pass; another trial will come and he will say, “This, this is the one!” Whoever would love to be kept away from the Fire and admitted to Paradise should meet death believing in Allah and the Last Day, and he should treat people in the manner he would love to be treated.
Whoever pledges allegiance to an imam, placing his hand in the imam’s and giving the commitment of his heart, must obey him to the best of his ability, for…’