The story of Herod’s slaughter of the innocents and Jesus’ flight to Egypt is found only in the Gospel of Matthew, has no historical coroborration outside of Matthew and is contradicted by Luke.
In the context of the story itself, an angel tells Joseph to flee to Egypt to escape the clutches of Herod. Joseph then returns to Bethlehem after Herod’s death (Matthew has the family originally living in Bethlehem, not Nazareth), but finds that Herod’s son, Archeleus, is now Tetrarch of Judea, so he moves his family up to Nazareth in Galilee (which was under the control of another of Herod’s son, Herod Antipas, so I don’t know why it would have been safer, but whatever). No mention is made in Matthew’s story of bodyguards.
Luke’s own nativity story is quite different and contradicts Matthew in a number of ways. Luke dates the birth ten years later than Matthew[sup]1[/sup], has Joseph and Mary living in Nazareth from the start rather than relocating there as Matthew does, has no slaughter of the innocents, magi or star, and no flight to Egypt. Luke has Jesus’ family returning to Nazareth immediately after his circumcision and presentation at the Temple (8 days after his birth). Matthew also has the family living in a house in Bethlehem, not a stable, and implies that Jesus was already two years old before the flight to Egypt.
There is no information in the Canonical Gospels about whether Jesus thought he was God when he was child. With the exception of his vist to the Temple at 12, the Gospels tell us nothing about Jesus’ life from the time of his infancy until his baptism by John and the start of his ministry at age 30. The closest thing the Gospels describe to an epiphany for Jesus is in Mark 1:9-11 when the Holy Spirit descends on Jesus “like a dove” after his baptism and says, “this is my son with whom I am well pleased.” This is arguably an “adoptionist”[sup]2[/sup] stance taken by Mark, rather than a realization of personal godhood, though.
[sup]1[/sup]Herod died in 4 BCE, the census of Quirinius mentioned by Luke occured in 6 CE. While Herod the Great was in power, Judea was a client kingdom, not a province, and not subject to Roman censuses or taxes. The tetrarchy of Judea was annexed as part of the province of Syria in 6 CE (after the Romans were forced to remove Archeleus from power for gross incompetence), and the first order of business for the then Syrian Governor, Quirinius, was to impose a census and tax. This census would not have been applicable in Galilee, incidentally, nor did it require anyone to travel to their ancestral homes.
[sup]2[/sup]an early sectarian belief that God “adopted” Jesus as his son as an adult and imbued him with the Holy Spirit, as opposed to the belief that Jesus was born as God incarnate.