There is no obedience when it results in disobedience of Allah

Narrated `Ali:

                    **The Prophet (ﷺ) , sent an army and appointed some man their commander. The man made a fire and then  said (to the soldiers), "Enter it." Some of them intended to enter it while some others said, 'We have  run away from it (i.e., embraced Islam to save ourselves from the 'fire')." They mentioned that to the  Prophet, and he said about people who had intended to enter the fire. ''If they had entered it, they  would have remained In it till the Day of Resurrection.'' 

Then he said to others, “No obedience for evil deeds, obedience is required only in what is good .”**

[Sahih Al-Bukhari Hadith No. 7257]

This Hadith lays down a fundamental principle of Islam. There is no obedience of anyone in matters which result in disobedience of Allah.

If your parents order you to do something which results in disobedience of Allah, you are not to obey them.
if your husband orders you to do something which results in disobedience of Allah, you are not to obey him.
If your teacher orders you to do something which results in disobedience of Allah, you are not to obey him.
If your Sheikh orders you to do something which results in disobedience of Allah, you are not to obey him.
If your boss orders you to do something which results in disobedience of Allah, you are not to obey him.
If the ruler of the time orders you to do something which results in disobedience of Allah, you are not to obey him.

Also note that the commander of the army was appointed by the Messenger of Allah (sallallaahu 'alayhi wa sallam) himself. Yet, when the Companions (may Allah be pleased with them) saw that he ordered them with that which was a sin, they still disobeyed him which turned out to be the correct decision as attested by the mercy to all of mankind (sallallaahu 'alayhi wa sallam).