The massacre took place in the city of Bethlehem not in Judea which is where John the Baptist was born. So John the Baptist didn't have the problem that Jesus had
There is not one speck of historical evidence that any such event really happened. Chances are the author of Matthew's gospel was trying to draw parallels between Jesus and Moses as well as have an excuse to have Jesus born in Bethlehem but raised in Nazareth.
His mother took him out into the wilderness. His father, a priest, was killed for refusing to reveal where his wife and child were.
Mat 23:35 so that on you may come all the righteous blood shed on earth, from the blood of righteous Abel to the blood of Zechariah (father of John the baptist) the son of Barachiah, whom you murdered between the sanctuary and the altar.