The Gospels of Matthew and Luke perspire mightily to identify Jesus as the Jewish Messiah. They expend the effort because toward the end of the 1st century, when the Jesus narrative was being pulled together, early Christians didn't think they were founding a new religion; they thought they were fulfilling an old religion's promise of a Messiah. The problem: Some of Jesus' biography didn't fit the Messiah profile.
Prophecies of Isaiah, Jeremiah and Micah had spawned a tradition that the Messiah would spring from the line of King David. So Matthew and Luke string out long genealogies of Jesus that lead straight back to the great monarch -- through Mary's husband, Joseph. Too bad Joseph isn't Jesus' actual dad, since both evangelists attach paternity to the Holy Spirit. Scratch the David link.
But wasn't Jesus born in Bethlehem of Judea, which Micah 5:2 locates as the birthplace of the Messiah?
Luke reports Jesus' hometown as Nazareth in Galilee, several days' donkey ride to the north of Bethlehem, across mountains. To get Jesus born in Bethlehem, Luke must posit a taxation system that requires each family to return to its ancestral home and be registered -- a puzzle of bureaucratic motivation and citizen logistics that has never been solved.
Matthew, meanwhile, simply says Jesus was born in Bethlehem of Judea, but the family had to go hide in Egypt because the magi told King Herod a new ruler had just been born, which menace spurred Herod to kill all the Bethlehem babies. (The mass slaughter appears in no other historical account, including the other three Gospels.) Since all observers agreed that Jesus hailed from Nazareth, Matthew has Joseph dream that the family must move there in order to fulfill a prophecy that "He shall be called a Nazorean." Nice try; however, the passage Matthew cites, Judges 13:5, is about Samson, not the Messiah, and the text reads not "Nazorean" but "nazirite," a person who takes a special religious vow.
Fun fact: There was another Bethlehem -- not in Judea but in Galilee, seven miles northwest of Nazareth. You could walk it in three hours.
So maybe that's the basis of the tradition that Jesus was born in Bethlehem: He was. Just not the right Bethlehem.