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:60:1In the name of Allah, the Entirely Merciful, the Especially Merciful.

O you who have believed, do not take My enemies and your enemies as allies, extending to them affection while they have disbelieved in what came to you of the truth, having driven out the Prophet and yourselves ˹only˺ because you believe in Allah, your Lord. If you have come out for jihad in My cause and seeking means to My approval, ˹take them not as friends˺. You confide to them affection, but I am most knowing of what you have concealed and what you have declared. And whoever does it among you has certainly strayed from the soundness of the way.  

O you who believe, do not take My enemy and your enemy, namely, the disbelievers of Mecca, for friends. You offer, you communicate to, them, the Prophet’s plan (s) to attack them, which he had confided to you, and had kept secret, at Hunayn, ˹communicating this to them out of˺, affection, between you and them. Hātib b. Abī Balta‘a sent them a letter to that effect, on account of his having children and close relatives, idolaters, among them. The Prophet (s) intercepted it from the person to whom he ˹Hātib˺ had given it to deliver, after God apprised him of this. Hātib’s excuse for this ˹conduct of his˺ was accepted ˹by the Prophet˺; when verily they have disbelieved in the truth that has come to you, that is, ˹in˺ the religion of Islam and the Qur’ān, expelling the Messenger and you, from Mecca, by oppressing you, because you believe in God, your Lord. If you have gone forth to struggle in My way and to seek My pleasure … (the response to the conditional is indicated by what preceded, that is to say, ˹understand it as being˺ ‘then do not take them as friends’). You secretly harbour affection for them, when I know well what you hide and what you proclaim. And whoever among you does that, that is, to secretly communicate the Prophet’s news to them, has verily strayed from the right way, he has missed the path of guidance (originally, al-sawā’ means ‘the middle ˹way˺’).
القرآن:٦٠:١بِسْمِ اللَّهِ الرَّحْمَٰنِ الرَّحِيمِ

يَا أَيُّهَا الَّذِينَ آمَنُوا لَا تَتَّخِذُوا عَدُوِّي وَعَدُوَّكُمْ أَوْلِيَاءَ تُلْقُونَ إِلَيْهِمْ بِالْمَوَدَّةِ وَقَدْ كَفَرُوا بِمَا جَاءَكُمْ مِنَ الْحَقِّ يُخْرِجُونَ الرَّسُولَ وَإِيَّاكُمْ ۙ أَنْ تُؤْمِنُوا بِاللَّهِ رَبِّكُمْ إِنْ كُنْتُمْ خَرَجْتُمْ جِهَادًا فِي سَبِيلِي وَابْتِغَاءَ مَرْضَاتِي ۚ تُسِرُّونَ إِلَيْهِمْ بِالْمَوَدَّةِ وَأَنَا أَعْلَمُ بِمَا أَخْفَيْتُمْ وَمَا أَعْلَنْتُمْ ۚ وَمَنْ يَفْعَلْهُ مِنْكُمْ فَقَدْ ضَلَّ سَوَاءَ السَّبِيلِ  

{يا أيها الذين آمنوا لا تتخذوا عدوي وعدوَّكم} أي كفار مكة {أولياء تلقون} توصلون {إليهم} قصد النبي ﷺ غزوهم الذي أسرَّوُ إليكم وَوَرَّى بحُنَين {بالمودة} بينكم وبينهم كتب حاطب بن أبي بلتعة إليهم كتابا بذلك لما له عندهم من الأولاد والأهل المشركين فاسترده النبي ﷺ ممن أرسله معه بإعلام الله تعالى له بذلك وقبل عذر حاطب فيه {وقد كفروا بما جاءكم من الحق} أي دين الإسلام والقرآن {يخرجون الرسول وإياكم} من مكة بتضييقهم عليكم {أن تؤمنوا} أي لأجل أن آمنتم {بالله ربكم إن كنتم خرجتم جهادا} للجهاد {في سبيلي وابتغاء مرضاتي} وجواب الشرط دل عليه ما قبله، أي فلا تتخذوهم أولياء {تُسرون إليهم بالمودة وأنا أعلم بما أخفيتم وما أعلنتم ومن يفعله منكم} أي إسرار خبر النبي إليهم {فقد ضل سواء السبيل} أخطأ طريق الهدى، والسواء في الأصل الوسط.