Matthew chapter 2 covers a period of time that must have extended into years. From the birth of Jesus in Bethlehem to the setting up of home in Nazareth following the death of Herod, king of Judea.
Luke chapter 2 covers the period from the tax decree issued by Augustus to the time that Jesus was twelve years old and in Jerusalem for Passover.
Here is how the two gospel accounts can be married together without there being any contradiction:
Luke 2:1-7 Jesus is born
Luke 2:8-16 Shepherds visit
[Notice verse 17, 'And when..', time passes]
Luke 2:21 Circumcision [Brit Milah at 8 days old according to the law of Moses, Leviticus ch. 12:3]
Luke 2:22-38 Purification of Mary and sacrifice of 'A pair of turtledoves, or two young pigeons'.[Leviticus 12:4-8, this sacrifice must have taken place 33 days after the circumcision of Jesus]
Now we turn to Matthew's gospel to follow the chronological order of events. In Matthew 2:1-12 we read of the visit of the wise men to see the 'young child'. In verse 12, it says that the wise men 'come into the house' in Bethlehem [notice, no mention of a stable or manger]
Notice verse 13 begins, 'And when..' so time has passed. An angel warns Joseph of the threat from Herod and the family depart for Egypt. They remain in Egypt until the death of Herod, king of Judea. While they are away Herod slaughters all the children 'two years old and under'. This is significant because it shows that Herod must have been calculating the time to ensure he killed the threat to his throne.
In verse 19 we read, 'But when..' and are told that Herod was dead. Joseph is now visited by an angel and told it is safe to return to Israel. Archelaus now ruled in Judea, so avoiding Judea they go to Galilee to 'the city called Nazareth'.
We now return to Luke's gospel to pick up the tail-end the story. In Luke 2:39 we read, 'And when..' suggesting that time has passed, and the words,'And when they had performed all things according to the law of the Lord, they returned into Galilee, to their own city Nazareth. And the child grew, and waxed strong in spirit...' (verse 40)
The reason that people get confused is that they assume that the words 'performed all things according to the law of the Lord' refers only to the circumcision and purification of the previous verses, when in fact it must also encompass the fulfilment of the word by the prophet; 'Out of Egypt have I called my son.'[Hosea 11:1 and Matthew 2:15]
When Mary and Joseph went back to Nazareth, they went to set up a home together. There is no indication that they lived together before leaving Nazareth to go to Bethlehem. In fact, in Matthew 2:5 it says he went 'To be taxed with Mary his ESPOUSED wife, being great with child.'
I hope this careful reading of the text shows that you cannot cast sweeping aspersions on God's word without showing that you can back it up with documentary evidence.