David's rise to become the undisputed king over the entire nation of Israel fundamentally shifts the balance of power in the region, triggering an immediate military response from the Philistines. Up until this point, the Philistines viewed David merely as a minor tribal leader, an ally to the king of Gath, or a useful asset in their ongoing conflict with the house of Saul. His ascension to national leadership is perceived as a direct violation of past alliances. At the very least, it prompts the Philistines to test whether the new king will submit to their authority and pay tribute [מלבי״ם, חומת אנך, ביאור שטיינזלץ]. On the other hand, some suggest the Philistines clearly remember David's exceptional bravery and recognize him as a far greater threat than Saul ever was, prompting them to launch a preemptive strike [אלשיך].
Understanding the magnitude of David's strength, the Philistines realize that a standard military force will not suffice. They are forced to mobilize their entire army for a massive campaign [מצודת דוד, אלשיך]. This overwhelming gathering of forces serves as the historical backdrop for the composition of the psalm that asks why the nations rage [רד״ק]. The primary objective of this massive mobilization is highly personal: to hunt David down, capture him, and direct the entire war effort specifically against him [רד״ק, אברבנאל, ביאור שטיינזלץ, אלשיך].
In response to this severe threat, David relocates to a stronghold. The primary approach among commentators is that this was a heavily fortified defensive tower. He travels down to this location because the fortress is situated at a lower elevation than Jerusalem [רד״ק, אברבנאל]. A differing perspective suggests the stronghold is located in the desert of Maon, near Philistine territory, a familiar place where David previously hid from Saul [מלבי״ם]. However, now bearing the responsibilities of a king, David can no longer simply flee into the deep desert as he did during his years of wandering. Instead, he must establish a fortified position to withstand the enemy invasion [ביאור שטיינזלץ].
Moving to the stronghold is by no means a retreat. Rather, it is a calculated tactical and spiritual preparation. David enters the fortress to gather his strength and wait so he can ask God for specific direction on how to proceed [מצודת דוד, רד״ק, אלשיך, רלב״ג]. While the Philistine forces spread out across the higher elevations, David patiently remains in the lower stronghold, waiting for divine guidance before advancing to engage them in battle [רד״ק].