Caution: Translations of Quran and Ḥadīth may lead to possible misapplications and misinterpretations. This site is intended for students of sacred knowledge that are proficient in comprehending classical Arabic and have a strong foundation in Islamic sciences. Also note that religious injunctions rely on several aspects beyond what one may glean through reading individual aḥādīth.
quran:4:59

O you who have believed, obey Allah and obey the Messenger and those in authority among you. And if you disagree over anything, refer it to Allah and the Messenger, if you should believe in Allah and the Last Day. That is the best ˹way˺ and best in result.  

O you who believe, obey God, and obey the Messenger and those in authority among you, that is, rulers, when they command you to obey God and His Messenger. If you should quarrel, disagree, about anything, refer it to God, that is, to His Book, and the Messenger, while he lives, and thereafter ˹refer˺ to his Sunna: in other words examine these ˹disputes˺ with reference to these two ˹sources˺, if you believe in God and the Last Day; that, reference to the two ˹sources˺, is better, for you than quarrelling or ˹adhering to˺ personal opinions, and more excellent in interpretation, in the end.
القرآن:٤:٥٩

يَا أَيُّهَا الَّذِينَ آمَنُوا أَطِيعُوا اللَّهَ وَأَطِيعُوا الرَّسُولَ وَأُولِي الْأَمْرِ مِنْكُمْ ۖ فَإِنْ تَنَازَعْتُمْ فِي شَيْءٍ فَرُدُّوهُ إِلَى اللَّهِ وَالرَّسُولِ إِنْ كُنْتُمْ تُؤْمِنُونَ بِاللَّهِ وَالْيَوْمِ الْآخِرِ ۚ ذَٰلِكَ خَيْرٌ وَأَحْسَنُ تَأْوِيلًا  

{يا أيها الذين آمنوا أطيعوا الله وأطيعوا الرسول وأولي} وأصحاب {الأمر} أي الولاة {منكم} إذا أمروكم بطاعة الله ورسوله {فإن تنازعتم} اختلفتم {في شيء فردوه إلى الله} أي إلى كتابه {والرسول} مدة حياته وبعده إلى سنته أي اكشفوا عليه منهما {إن كنتم تؤمنون بالله واليوم الآخر ذلك} أي الرد إليهما {خير} لكم من التنازع والقول بالرأي {وأحسن تأويلاً} مآلاً.