So they defeated them by permission of Allāh, and David killed Goliath, and Allāh gave him the kingship and wisdom [i.e., prophethood] and taught him from that which He willed. And if it were not for Allāh checking [some] people by means of others, the earth would have been corrupted, but Allāh is the possessor of bounty for the worlds.
Verse 249: قَالَ إِنَّ اللَّـهَ مُبْتَلِيكُم بِنَهَرٍ (He said: Allah is going to test you by a
river).
The wisdom behind this test, as perceived by this humble commentator, appears to be as follows. Not difficult to imagine is the excitement created on such occasions but there are not many who would stay firm in their hour of trial. And should such a time come, the weakness shown by such people becomes contagious making others panic as well. Allah Almighty willed that such people be pruned out. This purpose was accomplished by this test, which is very appropriate, because steadfastness is necessary in fighting. So, being patient, when water is made available without asking in a state of intense thirst, is a proof of steadfastness, and dashing for water is a proof of its absence. Later on comes the unusual: Those who drank too much water became mysteriously more incapacitated. This has appeared in Ruh al-Ma'ani on the authority of Ibn Abi Haim from Ibn ` Abbas ؓ . Now the events and sayings mentioned in this story tell us that there were three kinds of people among them:
(1) The weak in faith who failed to make the grade in their hour of
trial.
(2) The perfect who fully succeeded in their trial but did feel concerned about how low they were in numbers.
(3) The most perfect who did not bother even about that.
Tazkirul Quran
Maulana Wahiduddin KhanOn ayahs 250–251
What is essential to gain a victory in any such encounter is that the participants must have the capacity to persevere, whatever the odds, and must obey their leader. Saul forbade his soldiers to drink water from the river in order to test their obedience and perseverence. According to the Bible, only 600 out of the whole army were able to refrain from drinking water. Those who could not resist drinking it were confirmed in their moral weakness. That was why they were all the more terrified at the sight of the apparently strong army of their enemies. But those who had not drunk the river water had by their obedience confirmed their patience and endurance. Then they realized that God alone brought defeat or granted victory. In the words of the Bible, ‘Then all this assembly shall know that the Lord does not save with sword and spear, for the battle is the Lord’s and He will give you into our hands’ (1 Samuel, 17:47 ).
Uthmani text of the Madinah mushaf (King Fahd Complex). Translation: Saheeh International. Tafsir via Quran.com.