The holy innocents were from Bethlehem and its vincity:
[Herod] ordered the massacre of all the boys in Bethlehem and its vicinity two years old and under, in accordance with the time he had ascertained from the magi.
John the Baptist is not described as being born in Bethlehem but simply a hill town in Judea:
During those days Mary set out and traveled to the hill country in haste to a town of Judah, where she entered the house of Zechariah and greeted Elizabeth.
A tradition amongst Christians in the Holy Land has marked Ein Kerem/Carem as the birthplace of John the Baptist. However this is not considered certain. As the Catholic Encyclopedia notes:
A far stronger objection is deduced from the silence of early writers, notably of St. Jerome, who wrote an ex professo treatise on the Biblical places of the Holy Land; and, as a matter of fact, the tradition concerning 'Ain Karim has never been recognized as conclusive by the scholars, either ancient or modern, who have written commentaries on the New Testament…
…Nevertheless, some modern Catholic writers, among whom is Victor Guerin, still adhere to the tradition of 'Ain Karim; but in the absence of positive early documentary evidence the controversy cannot be definitely settled.
Of his upbringing we are told only that he was in the desert of Judea:
The child grew and became strong in spirit, and he was in the desert until the day of his manifestation to Israel.
So given that we don’t know what city John was born in and we don’t know when he went into the desert, it is nearly impossible to give an explanation that isn’t pure conjecture.
Perhaps the town that John was born in was outside the radius that Herod had declared in his murderous order. Perhaps John’s family had already moved away from the region. Perhaps they had been warned in a dream in a manner similar to St. Joseph.
In a certain sense there doesn’t need to be an explanation because there is nothing to refute.