The Day every soul will find what it has done of good present [before it] and what it has done of evil, it will wish that between itself and that [evil] was a great distance. And Allāh warns you of Himself, and Allāh is Kind to [His] servants."
Allah tells His servants that He knows the secrets and apparent matters and that nothing concerning them escapes His observation. Rather, His knowledge encompasses them in all conditions, time frames, days and instances. His knowledge encompasses all that is in heaven and earth, and nothing not even the weight of an atom, or what is smaller than that in the earth, seas and mountains, escapes His observation. Indeed,
وَاللَّهُ عَلَى كُلِّ شَيْءٍ قَدِيرٌ
(And Allah is able to do all things.) and His ability encompasses everything. This Ayah alerts Allah's servants that they should fear Him enough to not commit what He prohibits and dislikes, for He has perfect knowledge in all they do and is able to punish them promptly. And He gives respite to some of them, then He punishes them, and He is Swift and Mighty in taking account. This is why Allah said afterwards,
In these verses, Muslims have been instructed not to take disbelievers as their friends. Those who act against this instruction have been sternly warned: Those who take them as friends will find that their bond of love and friendship with Allah has been cut off. Any emotionally involved friendship that comes from the heart is absolutely forbidden (Haram). However, a formal friendship at the level of mutual dealings is, no doubt, permissible; but, that too is not favoured if unnecessary.
Verses dealing with this subject have appeared at many places in the Holy Qur'an with varying shades of meaning. It was said in Surah al-Mumtahinah:
A believer treats all human beings with justice and fairness, without differentiating between Muslims and non-Muslims. But friendship with non-Muslims who are at war with Islam is not lawful. In the eyes of God, it is our intention that matters: when our intention is sincere, God does not take us to task for our actions. The key factor, worthy of consideration in all matters, is the fear of God. One should always give proper thought to one’s behaviour, whatever the issue, because one is accountable to God for everything. Whoever is proved wrong on the divine scale cannot escape punishment. Nothing pertaining to human beings escapes the eyes of God, whether in public or in private. When the veil of the divine test is cast aside, the world of the Hereafter will appear before mankind and the fruits of all man’s actions will be before him. This sight will be so dreadful that all the things of this world which had appeared so pleasing to him, will now be the very things from which he will want to distance himself. What is most important in the eyes of God is whether Islam is implanted in one’s heart or not. A believer is one whose love for God springs from his heart, who loves God truly in his heart of hearts. It is people such as those who deserve God’s love and attention. One who forms such a bond with God is forgiven by Him for his failings. God is hard on the arrogant. But He is gentle with those who adopt modesty as their way of life.
Uthmani text of the Madinah mushaf (King Fahd Complex). Translation: Saheeh International. Tafsir via Quran.com.