Allah says in surah al-Mumtahinah:
لَّا يَنْهَاكُمُ اللَّـهُ عَنِ الَّذِينَ لَمْ يُقَاتِلُوكُمْ فِي الدِّينِ وَلَمْ يُخْرِجُوكُم مِّن دِيَارِكُمْ أَن تَبَرُّوهُمْ وَتُقْسِطُوا إِلَيْهِمْ ۚ إِنَّ اللَّـهَ يُحِبُّ الْمُقْسِطِينَ * إِنَّمَا يَنْهَاكُمُ اللَّـهُ عَنِ الَّذِينَ قَاتَلُوكُمْ فِي الدِّينِ وَأَخْرَجُوكُم مِّن دِيَارِكُمْ وَظَاهَرُوا عَلَىٰ إِخْرَاجِكُمْ أَن تَوَلَّوْهُمْ ۚ وَمَن يَتَوَلَّهُمْ فَأُولَـٰئِكَ هُمُ الظَّالِمُونَ
Allah does not forbid you to deal justly and kindly with those who did not fight against you on account of religion and did not drive you out of your homes. Verily, Allah loves those who deal justly. * It is only those who fought against you on account of religion and drove you out of your homes, and helped to drive you out that Allah forbids you to take as friends and allies. And whosoever will befriend them, then such are the wrongdoers. [60:8-9]
The great scholar Ibn al-Qayyim mentioned the following point regarding these ayaat:
فإن الله سبحانه لما نهى في أول السورة عن اتخاذ المسلمين الكفار أولياء وقطع المودة بينهم وبينهم ، توهم بعضهم أن برهم والإحسان إليهم من الموالاة والمودة ، فبين الله سبحانه أن ذلك ليس من الموالاة المنهي عنها ، وأنه لم ينه عن ذلك بل هو من الإحسان الذي يحبه ويرضاه ، وكتبه على كل شيء ، وإنما المنهي عنه تولي الكفار والإلقاء إليهم بالمودة
When Allah prohibited the Muslims from taking the disbelievers as close friends and allies and cut off the affection between them at the beginning of this surah [60:1], some might think that birr and ihsan – good behavior and excellent treatment – towards them would fall under those prohibited categories of close friendship and affection.
So Allah clarified that these things are not part of the close relationships that He had prohibited, and that He does not prohibit the believers from them. On the contrary, birr and ihsan towards them falls within the excellent behavior which Allah loves and is pleased with, and which He has ordained for everything. What is prohibited is only taking the disbelievers as close friends and allies and meeting them with love and affection.
[Ahkaam Ahl al-Dhimmah 1/301]
See also: Love in the Qur’an Series
See also: Three Categories of Love: Imam al-Sa’di