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:49:7

And know that among you is the Messenger of Allah. If he were to obey you in much of the matter, you would be in difficulty, but Allah has endeared to you the faith and has made it pleasing in your hearts and has made hateful to you disbelief, defiance and disobedience. Those are the ˹rightly˺ guided.  

And know that the Messenger of God is among you, so do not speak falsehood, for God will inform him of the ˹real˺ state of affairs. If he were to obey you in many matters, which you communicate contrary to reality, so that the necessary ˹evil˺ consequences ensue, you would surely be in trouble, you would earn in addition to that sin, the sin for the consequences that ensue ˹from your error˺. But God has endeared faith to you, adorning your hearts with it, and He has made odious to you disbelief and immorality and disobedience (˹an instance of˺ suppletion with respect to import, as opposed to ˹lexical˺ form; for the one to whom ‘faith has been endeared …’ and so forth, will naturally be dissimilar in character to the mentioned ˹reprobate˺). Those (there is here a shift from the second ˹to the third˺ person address) — they are the right-minded, the ones firmly established upon ˹the way of˺ their religion;
القرآن:٤٩:٧

وَاعْلَمُوا أَنَّ فِيكُمْ رَسُولَ اللَّهِ ۚ لَوْ يُطِيعُكُمْ فِي كَثِيرٍ مِنَ الْأَمْرِ لَعَنِتُّمْ وَلَٰكِنَّ اللَّهَ حَبَّبَ إِلَيْكُمُ الْإِيمَانَ وَزَيَّنَهُ فِي قُلُوبِكُمْ وَكَرَّهَ إِلَيْكُمُ الْكُفْرَ وَالْفُسُوقَ وَالْعِصْيَانَ ۚ أُولَٰئِكَ هُمُ الرَّاشِدُونَ  

{واعلموا أن فيكم رسول الله} فلا تقولوا الباطل فإن الله يخبره بالحال {لو يطيعكم في كثير من الأمر} الذي تخبرون به على خلاف الواقع فيرتب على ذلك مقتضاه {لعنتُّم} لأثمتم دونه إثم التسبب إلى المرتب {ولكن الله حبَّب إليكم الإيمان وزينه} حسنه {في قلوبكم وكرَّه إليكم الكفر والفسوق والعصيان} استدراك من حيث المعنى دون اللفظ لأن من حبب إليه الإيمان إلخ غايرت صفته صفة من تقدم ذكره {أولئك هم} فيه التفات عن الخطاب {الراشدون} الثابتون على دينهم.