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:76:24

So be patient for the decision of your Lord and do not obey from among them a sinner or ungrateful ˹disbeliever˺.  

So submit patiently to your Lord’s decree, to you to deliver His Message, and do not obey of them, that is, ˹of˺ the disbelievers, any sinner or disbeliever, namely, ‘Utba b. Rabī‘a and al-Walīd b. al-Mughīra — both of whom said to the Prophet (s), ‘Abandon this affair of yours!’; it is also possible that what is meant is every sinner or disbeliever, in other words, ‘Do not obey any of these, whichever of the two he may be, in what he may summon you to of sin or disbelief’.
القرآن:٧٦:٢٤

فَاصْبِرْ لِحُكْمِ رَبِّكَ وَلَا تُطِعْ مِنْهُمْ آثِمًا أَوْ كَفُورًا  

{فاصبر لحكم ربك} عليك بتبليغ رسالته {ولا تطع منهم} أي الكفار {آثما أو كفورا} أي عتبة بن ربيعة والوليد بن المغيرة قالا للنبي ﷺ ارجع عن هذا الأمر. ويجوز أن يراد كل آثم وكافر أي لا تطع أحدهما أَيا كان فيما دعاك إليه من إثم أو كفر.