The Messenger of Allah ﷺ said, "Obedience to the leader is a duty upon every Muslim, so long as he does not command disobedience to Allah. But if he commands disobedience to Allah, then there is no obedience owed to him."
قال رسول الله ﷺ: طاعة الإمام حق على المرء المسلم ما لم يأمر بمعصية الله، فإذا أمر بمعصية الله فلا طاعة له.
Tammam narrated it in his Fawaid (914 - Rawd), from Hasan bin Habib, who said, Badr bin Haytham told us, Sulayman bin Abdul-Rahman told us, Abdul-Rahman bin Mighra told us, from Ubaydullah bin Umar, from Saeed bin Abu Saeed Maqburi, from his father, from Abu Hurairah, and he mentioned it.Its isnad is hasan because of Abdul-Rahman bin Mighra, for he is truthful, though criticism was directed at his narration from Amash, and this hadith is not from that category. Likewise, Sulayman bin Abdul-Rahman, who is the son of the daughter of Shurahbil, is of hasan narration.