What ye suffered on the day the two armies Met, was with the leave of Allah, in order that He might test the believers,-
And that He might know the hypocrites, unto whom it was said: Come, fight in the way of Allah, or defend yourselves. They answered: If we knew aught of fighting we would follow you. On that day they were nearer disbelief than faith. They utter with their mouths a thing which is not in their hearts. Allah is Best Aware of what they hide.
(They are) the ones that say, (of their brethren slain), while they themselves sit (at ease): “If only they had listened to us they would not have been slain.” Say: “Avert death from your own selves, if ye speak the truth.”
These verses explain the wisdom behind the trial that the Muslims faced. It was by the commandment of Allah and its purpose was to separate the true believers from the hypocrites, so that everyone would know who, in their community, were trustworthy and dependable and those who were not. This trial was necessary for the purgation of the Muslim community. If the true and sincere Muslims and the hypocrites were left unsorted as before, the rot could affect and ultimately destroy the entire community.
Wa qīla lahum ta‘ālaw (These were told: “Come …) refers to a group of the hypocrites who were called upon to join and participate in jihād on this occasion, reminding them of the reward for their efforts, whether they were victorious or the enemy backed down, the purpose of defending the community would be achieved. But they did not respond to this call for jihād and instead tried to cover their hypocrisy and cowardice by insisting that they did not believe there would be any fight between the Muslims and their enemies. Moreover, they made out that if they believed there would be fighting, they would surely have gone forth to fight. The Qur’ān comments that they were nearer to unbelief (kufr) than belief (īmān) while they offered these false excuses to cover their weakness, hypocrisy and cowardice. They uttered with their mouths what was not in their hearts for Allah knew what they concealed in their hearts.
The Qur’ān says that they sat back in their homes, and while some of their friends and relatives joined the jihād and were killed, they said that had these people listened to them and remained at their homes like them they would not have been killed. They thus betrayed their motive, the fear of death, for not joining the jihād. That was the real reason why they so desperately tried to avoid joining the jihād. What really held them back was their cowardice and hypocrisy. They falsely excused themselves saying that they did not see any possibility of war. At the end, the Qur’ān asks them that if they were so versed in matters of life and death, they should first of all try to save themselves from their own doom.
Islahi, Amin Ahsan. Pondering Over The Qur’an: Surah Ali Imran (pp. 300-301). Islamic Book Trust. Kindle Edition.