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:3:28

Let not believers take disbelievers as allies rather than believers. And whoever ˹of you˺ does that has nothing with Allah, except when taking precaution against them in prudence. And Allah warns you of Himself, and to Allah is the ˹final˺ destination.  

Let not the believers take the disbelievers as patrons, rather than, that is, instead of, the believers — for whoever does that, that is, ˹whoever˺ takes them as patrons, does not belong to, the religion of, God in anyway — unless you protect yourselves against them, as a safeguard (tuqātan, ‘as a safeguard’, is the verbal noun from taqiyyatan), that is to say, ˹unless˺ you fear something, in which case you may show patronage to them through words, but not in your hearts: this was before the hegemony of Islam and ˹the dispensation˺ applies to any individual residing in a land with no say in it. God warns you, He instills fear in you, of His Self, ˹warning˺ that He may be wrathful with you if you take them as patrons; and to God is the journey’s end, the return, and He will requite you.
القرآن:٣:٢٨

لَا يَتَّخِذِ الْمُؤْمِنُونَ الْكَافِرِينَ أَوْلِيَاءَ مِنْ دُونِ الْمُؤْمِنِينَ ۖ وَمَنْ يَفْعَلْ ذَٰلِكَ فَلَيْسَ مِنَ اللَّهِ فِي شَيْءٍ إِلَّا أَنْ تَتَّقُوا مِنْهُمْ تُقَاةً ۗ وَيُحَذِّرُكُمُ اللَّهُ نَفْسَهُ ۗ وَإِلَى اللَّهِ الْمَصِيرُ  

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