17 When the Philistines heard that David had been anointed king of Israel, they mobilized all their forces to capture him. But David was told they were coming, so he went into the stronghold. 18 The Philistines arrived and spread out across the valley of Rephaim. 19 So David asked the Lord, "Should I go out to fight the Philistines? Will you hand them over to me?" The Lord replied to David, "Yes, go ahead. I will certainly hand them over to you." 20 So David went to Baal-perazim and defeated the Philistines there. "The Lord did it!" David exclaimed. "He burst through my enemies like a raging flood!" So he named that place Baal-perazim (which means "the Lord who bursts through"). 21 The Philistines had abandoned their idols there, so David and his men confiscated them. 22 But after a while the Philistines returned and again spread out across 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.