The historical narrative briefly pauses its account of King Solomon's vast construction projects to explain the unique backstory of Gezer and how it became part of the Israelite kingdom [מלבי״ם, ביאור שטיינזלץ]. Gezer was once a powerful, heavily fortified Canaanite stronghold that had successfully resisted capture, remaining unconquered even by King David. Its independence finally ended when Pharaoh, the king of Egypt, launched a military campaign. He breached the city, killed its Canaanite inhabitants, and burned the fortress to the ground.
After capturing the city, which sat within the borders of Solomon's kingdom, Pharaoh chose to give the territory to his daughter upon her marriage to King Solomon. Commentators generally understand this transfer as a customary wedding gift sent to a bride [רד״ק, רלב״ג, מצודת דוד], while others specify that it functioned as a formal dowry [רש״י, ביאור שטיינזלץ]. Through this Egyptian military conquest, the territory passed into Solomon's possession. Because the city had been completely destroyed by fire during the invasion, Solomon was left with the necessary task of rebuilding and refortifying it [מלבי״ם, ביאור שטיינזלץ].