Jesus was born in Bethlehem because his family was from Bethlehem. They were there as a result of the census requiring everyone to travel to their hometown. So King David was also from Bethlehem. Ancient Israel was a bit bigger than it is today.