A divine message arrives during a turbulent historical window, caught between the marching armies of two massive empires: Egypt and Babylon. The prophecy serves as a dire warning concerning the fate of the Philistines [רש״י, רד״ק].
The timing of this revelation is pinpointed to the tenth year of King Zedekiah's reign. At that moment, the Babylonian army had laid siege to Jerusalem. In an attempt to assist the kingdom of Judah, the Egyptian Pharaoh marched out with his military. The approaching Egyptian forces caused the Babylonians to retreat and temporarily lift their siege. However, Pharaoh abandoned the campaign and turned back toward Egypt.
On his return journey, Pharaoh attacked and destroyed the city of Gaza, which was part of the Philistine territory. The Philistine coastal cities operated as small, independent kingdoms that often defied the rule of larger empires. Because they had likely adopted a hostile stance toward Egypt, Pharaoh swiftly conquered the city [ביאור שטיינזלץ].
While the Egyptian assault was devastating, the true purpose of the prophecy is to warn of a far greater and more sweeping danger. Exactly when Pharaoh was attacking Gaza, God revealed to Jeremiah that the Babylonian army would soon sweep down from the north to strike the entire Philistine land [רד״ק].
There is a sharp contrast between these two military campaigns. While Pharaoh settled for attacking only Gaza, the Babylonian king Nebuchadnezzar was destined to bring total and absolute destruction to all the Philistine territories [מלבי״ם, אברבנאל]. This impending devastation was driven by strategic military goals. The Philistines were loyal allies to the cities of Tyre and Sidon. Because Nebuchadnezzar was actively waging war against Tyre, he resolved to systematically wipe out its allies first, ensuring they could not send reinforcements during his campaign [מלבי״ם, אברבנאל].