Muhammad bin al-Sabbah and Suwayd bin Saeed narrated to us, both saying that Abdullah bin Raja al-Makki narrated to them from Ubaydullah, from Nafi, from Ibn Umar, that the Messenger of Allah ﷺ said, "It is the duty of a Muslim to listen and obey, whether he likes it or dislikes it, unless he is commanded to commit a sin. If he is commanded to commit a sin, then there is no listening and no obeying."
حدثنا محمد بن رمح أنبأنا الليث بن سعد عن عبيد الله بن عمر عن نافع
ح و حدثنا محمد بن الصباح وسويد بن سعيد قالا حدثنا عبد الله بن رجاء المكي عن عبيد الله عن نافع عن ابن عمر أن رسول الله ﷺ قال على المرء المسلم الطاعة فيما أحب أو كره إلا أن يؤمر بمعصية فإذا أمر بمعصية فلا سمع ولا طاعة
Muslim recorded it in the Book of Leadership, chapter on the obligation to obey rulers in matters that do not involve disobedience and the prohibition of obeying them in matters that do, hadith no. 1839, from the hadith of Layth, by this route.