Why according to what some consider legend was Jesus born in Bethlehem?
Whether one takes the conservative view that the gospels were written from the fifties onwards, or the scholarly view that the first gospel was not even written until about 70 CE, it is not possible to say that the nativity stories are based on eyewitness testimony of events in the previous century. The authors knew that Jews believed King David to have been born in Bethlehem and longed for a Messiah, who would probably also be born in Bethlehem. The tradition behind this comes from Micah 5:2.
There is no legend of any kind. The Gospel accounts give a factual and eyewitness account of where Jesus was born, as foretold by the Prophet Micah.
2But thou, Bethlehem Ephratah, though thou be little among the thousands of Judah, yet out of thee shall he come forth unto me that is to be ruler in Israel; whose goings forth have been from of old, from everlasting. The Jews evidently understood this to refer to the Messiah's birthplace also, since this is what they told Herod. It is also another reason they rejected Jesus, since they wrongly believed Him to have been born in Nazareth. One thing which is sometimes overlooked by those who wish to narrow the application of his prophecy to a local clan is to ignore that no local clan can have existence from everlasting. This can only apply to the eternal Son of God.