يَٰٓأَيُّهَا ٱلَّذِينَ ءَامَنُوا۟ ٱذْكُرُوا۟ نِعْمَتَ ٱللَّهِ عَلَيْكُمْ إِذْ هَمَّ قَوْمٌ أَن يَبْسُطُوٓا۟ إِلَيْكُمْ أَيْدِيَهُمْ فَكَفَّ أَيْدِيَهُمْ عَنكُمْ ۖ وَٱتَّقُوا۟ ٱللَّهَ ۚ وَعَلَى ٱللَّهِ فَلْيَتَوَكَّلِ ٱلْمُؤْمِنُونَ
O you who have believed, remember the favor of Allah upon you when a people determined to extend their hands [in aggression] against you, but He withheld their hands from you; and fear Allah. And upon Allah let the believers rely.
Commentary
The subject of the first of the three verses given above has appeared earlier in Surah al-Nis-a' in almost the same words. The only difference is that the arrangement of words there (4:135) was: كُونُوا قَوَّامِينَ بِالْقِسْطِ شُهَدَاءَ لِلَّـهِ while, here (5:8), it has been said: كُونُوا قَوَّامِينَ لِلَّـهِ شُهَدَاءَ بِالْقِسْطِ (be steadfast for Allah as witnesses for justice). A delicate reason for the alternation in words appearing earlier and later in these two verses has been given by Abu Ha-an in his Tafsir Al-Bahr al-Muhit a gist of which is given below.
There are usually two causes which hold people back from doing justice and then make them do the unjust and the oppressive. The first one is taking the side of your own self, or that of your friends and relatives. Enmity with someone is the other cause. The verse in Su-rah al-Nis-a' is addressing itself to the first subject while this verse of Surah al-Ma'idah is oriented to the other.
Therefore, the words which follow this sentence in Surah Al-Nisa' وَلَوْ عَلَىٰ أَنفُسِكُمْ أَوِ الْوَالِدَيْنِ وَالْأَقْرَبِي that is, 'even though against yourselves or the parents, and the kinsfolk ...' After the sentence of Surah al-Ma'idah cited above, the words which follow in this verse are: وَلَا يَجْرِمَنَّكُمْ شَنَآنُ قَوْمٍ عَلَىٰ أَلَّا تَعْدِلُوا that is, And malice against a people should not bid you to not doing justice ...' So, the essential message of this verse of Surah al-Nisa' is: When it comes to doing justice, let nothing affect you, neither your own self, nor your parents, nor your relatives. If the demand of justice happens to be against them, stay with nothing but justice. The essence of this verse from Surah al-Ma'idah is that hostility against an enemy should not affect your sense of justice to the limit that you start working against the demands of justice to harm your enemy.
This is the reason why, by placing 'al-qist' (justice) first in the verse of the Surah al-Nisa', it was said: كُونُوا قَوَّامِينَ بِالْقِسْطِ شُهَدَاءَ لِلَّـهِ... be upholders of justice, witnesses for Allah ... ) and, by placing 'lillah' (for Allah) first in the verse of Surah al-Ma'idah, it was said: كُونُوا قَوَّامِينَ لِلَّـهِ شُهَدَاءَ بِالْقِسْطِ... be steadfast for Allah as witnesses for justice ) - though, both these modes serve the same purpose end-wise. It is obvious that a person who stands for justice will stand for none but Allah, and one who stands for none but Allah will do nothing but justice. But, when it comes to protecting personal interest or favouring friends and relatives, one may be tempted to justify the thought that the act of caring for relationships here is also for Allah. Therefore, by bringing in the word, 'al-qist' (justice) first at that point, the message given was that the concession which is contrary to justice cannot be for Allah. And in Surah al-Ma'idah, where the purpose was to enjoin justice with enemies, the word 'lillah' (for Allah) was brought in first, which took away the chances of sentimental attachments overpowering human nature. The point is, when you stand for Allah, the inevitable outcome should be an equal justice with enemies as well. …