(Later, when the territory of the Danites was lost to them, they went up and fought against Leshem, captured it, and put it to the sword. So they took possession of Leshem, settled there, and renamed it after their father Dan.)
After losing their territory, the Danites attack Leshem, capture it, settle there, and rename it Dan.
It explains how Dan comes to occupy a different place than the one first allotted.
40The seventh lot came out for the clans of the tribe of Dan: 41The territory of their inheritance included Zorah, Eshtaol, Ir-shemesh, 42Shaalabbin, Aijalon, Ithlah, 43Elon, Timnah, Ekron, 44Eltekeh, Gibbethon, Baalath, 45Jehud, Bene-berak, Gath-rimmon, 46Me-jarkon, and Rakkon, including the territory across from Joppa. 47(Later, when the territory of the Danites was lost to them, they went up and fought against Leshem, captured it, and put it to the sword. So they took possession of Leshem, settled there, and renamed it after their father Dan.) 48This was the inheritance of the clans of the tribe of Dan, including these cities and their villages.