The obligation of obeying leaders in matters that do not involve sin, but it is forbidden to obey them in sinful matters Sahih Muslim 1837 c
Arabic hadith text
وَحَدَّثَنَاهُ عُبَيْدُ اللَّهِ بْنُ مُعَاذٍ، حَدَّثَنَا أَبِي، حَدَّثَنَا شُعْبَةُ، عَنْ أَبِي عِمْرَانَ، بِهَذَا الإِسْنَادِ كَمَا قَالَ ابْنُ إِدْرِيسَ عَبْدًا مُجَدَّعَ الأَطْرَافِ
Translation
Abu 'Imran narrated this hadith with a slight change of wording.