17 Now when the Philistines heard that they had anointed David king over Israel, all the Philistines went up to search for David. And David heard of it and went down to the stronghold. 18 The Philistines also went and deployed themselves in the Valley of Rephaim. 19 So David inquired of the Lord, saying, "Shall I go up against the Philistines? Will You deliver them into my hand?" And the Lord said to David, "Go up, for I will doubtless deliver the Philistines into your hand." 20 So David went to Baal Perazim, and David defeated them there; and he said, "The Lord has broken through my enemies before me, like a breakthrough of water." Therefore he called the name of that place Baal Perazim. 21 And they left their images there, and David and his men carried them away. 22 Then the Philistines went up once again and deployed themselves in the Valley of Rephaim.
Matthew Henry's Commentary on 2 Samuel 5:17-22
Commentary on 2 Samuel 5:17-25
(Read 2 Samuel 5:17-25)
The Philistines considered not that David had the presence of God with him, which Saul had forfeited and lost. The kingdom of the Messiah, as soon as it was set up in the world, was thus attacked by the powers of darkness. The heathen raged, and the kings of the earth set themselves to oppose it; but all in vain, Acts 2:2.