‘Abd Allaah bin Masud reported the Apostle of Allaah ﷺ as saying “Listening and Obedience are binding on a Muslim whether he likes or dislikes, so long as he is not commanded for disobedience (to Allaah). If he is commanded to disobedience (to Allaah), no listening and disobedience are binding (on him). (Using translation from Abū Dāʾūd 2626)
أَنَّ رَسُولَ اللهِ ﷺ قَالَ السَّمْعُ وَالطَّاعَةُ عَلَى الْمَرْءِ الْمُسْلِمِ فِيمَا أَحَبَّ أَوْ كَرِهَ إِلَّا أَنْ يُؤْمَرَ بِمَعْصِيَةٍ فَإِنْ أُمِرَبِمَعْصِيَةٍ فَلَا سَمْعَ وَلَا طَاعَةَ