The Israelites only fought against the king of Gezer and his army when he came to help Lachish. They did not go up to the city of Gezer itself. This helps to explain why we read in Joshua 16:10 and Judges 1:29 that the population of Gezer was not completely destroyed.1 In the time of Solomon, the king of Egypt captured Gezer and gave it as a dowry to his daughter who married Solomon (1 Kings 9:16).
33 Then Horam king of Gezer came up to help Lachish. And Joshua struck him and his people, until he left none remaining.