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.
They defeated them by God’s will. The prophet of God, David, killed their leader Goliath and God gave him kingship and prophethood and taught him many sciences as He willed, including those that are beneficial for this world and those for the hearafter. If it were not the system of God to drive back the evil of some people by means of others, there would be corruption on earth as the evil ones would gain authority. However, God is Bountiful to all of His creation.