Messenger of Allah, what if we are ruled by leaders who do not follow your example and do not abide by your command? What do you order us to do regarding them?The Messenger of Allah ﷺ replied, "There is no obedience owed to one who does not obey Allah ."
حدثنا عبد الصمد حدثنا حرب بن شداد بصري حدثنا يحيى يعني ابن أبي كثير قال عمرو بن زنيب العنبري إن أنس بن مالك حدثه أن
يا رسول الله أرأيت إن كان علينا أمراء لا يستنون بسنتك ولا يأخذون بأمرك فما تأمر في أمرهم فقال رسول الله ﷺ لا طاعة لمن لم يطع الله عز وجل
No references are available.
Its chain of transmission is hasan. This is because of Amr bin Zaynab Anbari, about whom there is disagreement. Bukhari said nothing about him in Tarikh al-Kabir 6/332, Haythami did not identify him in 5/225, and Ibn Hibban mentioned him in al-Thiqat 5/174.The hadith with similar wording was narrated by Bukhari in 13/121, number 7144, in Fath al-Bari, in the chapter on rulings, on hearing and obeying the ruler, and by Tirmidhi in 4/209, number 1707, in the chapter on jihad, on there being no obedience to a created being in disobedience to the Creator, and by Nasai in 7/160, number 4206, in the chapter on the pledge of allegiance, on the recompense of one who commands disobedience, and by Ibn Majah in 2/956, number 2864, in the chapter on jihad, on there being no obedience in disobedience to Allah.