Shaykh Uthaymeen said, “…The commands from the leaders are of various categories:
The first category is those commands that its not permissible to obey them in that is, if a leader commands something of disobedience to Allah such as ordering one to shave his beard or commands other sinful acts.
Regarding such things, theres no obedience to him because,Allah says, “Oh you who believe, obey Allah and obey the Messenger and those in authority among you.” [Srah al-Nis, 4:59]
He connected the obedience to those in authority to the obedience of Allah and his Messenger without repeating the action (the verb: obey) again, indicating that the obedience to those in authority is conditional based upon the obedience to Allah and his messenger. The prophet also said, “Obideance is in that which is good.” (Bukhari and Muslim)
Meaning whatever does not contain anything of sins.
The prophet once sent a man on an expedition and instructed the people with him to obey him. One day, they angered the man so he ordered them to gather wood and they did. He then ordered them to start a large fire and they did. He then commanded them to throw themselves in it. They refused saying, “We only followed the messenger out of fear of the fire!” When they returned to the prophet, they informed him of the incident to which he said, “Indeed had they entered it they qoukd have come out from it. Obedience is only in that which is good.” (Bukhari and Muslim)
That is the first category.
The second category is when the leader commands whatever Allah commands or His Messenger of acts of worship.
So if they are religious obligations such as instructing the people to observe congregational prayer, then obedience here is mandatory from two perspectives:
1. Such acts are obligations in the Islamic legislation even if the leader had not ordered it.
2. The obligation is reinforced even more when the leader also commands it.
The third category is when he orders the performance of acts of worship that are not obligations yet are still legislated.
An example would be if he were to order the people to collectively pray to Allah for rain tomorrow and the supplication of the fasting person is accepted, so fast explicitly compulsory because this is an act of worship between the individual servant and his Lord, so obedience is not a direct obligation.
The Fourth Category
The fourth category is when the leader commands that which helps to preserve public safety and security and the general well-being of the society. In this case, obedience to him is an obligation even if Allah and His Messenger did not explicitly order it, and as long as it contains nothing of sin.
An example is the laws prevalent now which have been accepted; they do not contradict Islam at all. Its required to obey the leader regarding such laws, and whoever breaks these laws and opposes them, he is a sinner…”
Ref: Taken from the casette, Adf al-amalt al-miyyah id Wul Bild al-aramayn
Posted by Abdul Kareem Ibn Ozzie