The invasion of Jerusalem by a foreign military force is not a random geopolitical event, but a direct spiritual consequence. The attack is deeply tied to the moral condition of the nation, with God intervening immediately to signal to the leadership that they have strayed. In the fifth year of Rehoboam's reign, Shishak, who belonged to the Cushite dynasty ruling over Egypt, marched on Jerusalem [ביאור שטיינזלץ]. The underlying cause for this invasion was the nation's sudden rebellion and betrayal against God [מצודת ציון]. It was this very disloyalty that brought the enemy to their gates [מצודת דוד]. This connection is not a political justification claimed by the Egyptian king, but rather the true theological reality explaining the events [ביאור שטיינזלץ].
The specific timing of this invasion reflects the fulfillment of a promise God made to King David. God assured David that He would treat his royal dynasty just as a father treats his son. When a son strays from the right path, a loving father disciplines him right away to guide him back, never allowing him to ruin his life to the point of absolute destruction. This stands in sharp contrast to how God dealt with Jeroboam, where He allowed his wrongdoings to accumulate until his fate was sealed for total ruin. Rehoboam, however, faced immediate consequences. Because he abandoned the Torah in the fourth year of his reign, the Egyptian attack came just one year later.
The swift nature of this punishment highlights that God did not wait for a long list of sins to pile up. Instead, He delivered a harsh rebuke at the very onset of the nation's rebellion. Furthermore, this rapid turn of events served a practical lesson for Rehoboam, proving to him that the massive army he had carefully assembled was entirely useless when standing against a decree from God [מלבי״ם].