Abdullah bin Umar reported,

Ibn Umar رضي الله عنهم reported from the Prophet ﷺ. And Muhammad bin Sabbah narrated to me, saying Ismail bin Zakariyya narrated to us, from Ubaydullah, from Nafi, from Ibn Umar رضي الله عنهم, from the Prophet ﷺ, who said, "Listening and obedience are an obligation as long as one is not commanded to commit a sin. If one is commanded to commit a sin, there is no listening and no obedience."

Bukhari 2955

Sahih

حدثنا مسدد حدثنا يحيى عن عبيد الله قال حدثني نافع

عن ابن عمر رضي الله عنهما

عن النبي ﷺ ح و حدثني محمد بن صباح حدثنا إسماعيل بن زكرياء عن عبيد الله عن نافع عن ابن عمر رضي الله عنهما عن النبي ﷺ قال السمع والطاعة حق ما لم يؤمر بالمعصية فإذا أمر بمعصية فلا سمع ولا طاعة

البخاري 2955صحيح
Contents
Reference
Commentary
Ayat
Collection
Sahih Bukhari
Book
Jihad and expeditions
Chapter
Hearing and obeying the imam
Numbering
Darussalam 2955
Bukhari 2955