Question: In Matthew 2, right after the visit from the Magi, an angel of the Lord appeared in verse 13 and instructed Joseph to take Mary and Jesus to Egypt because their lives were in danger. In verse 14 the text says they got up and left immediately. In Luke 2, the shepherds went to Bethlehem to see what the angel told them regarding the birth of Jesus. Then verses 21-23 describe Jesus being taken to Jerusalem to be circumcised on the 8th day. These two passages seem to contradict each other.
Answer: Luke was undoubtedly aware of all that Matthew’s gospel contained because both knew the accounts of Jesus’ history which were the basis of their gospels. Each, however, chose different portions of those accounts to include in their gospels based on the audiences and purposes they had been given to communicate with.
When the Magi visit Jesus he and his family are living in a house. Herod has found out from the Magi when they had seen the star and orders all boys 2 years and under killed. This is likely because Jesus is over a year old at this time. In other words, after Jesus is taken to the Temple in Jerusalem by his parents to be dedicated, they return to Bethlehem and eventually find work and a house to live in. Later the Magi come and the events of Matthew 2 take place.
This means that Luke only records the first few weeks of Jesus’ life in his birth account and then he glides over the Egypt stay. What he says is not inaccurate but abbreviated. Matthew has the most detail and covers the most time of Jesus’ early childhood up to his return to Nazareth with his parents. Only Luke, of course, includes the account of Jesus around age 12 where he visits Jerusalem with his parents for Passover and remains behind discussing doctrine with the teachers of the law. Matthew does not include that incident because it does not fit his purpose.
Matthew, Mark and Luke all seem to be drawing from the same body of material but make different uses of the material and include or exclude different portions of it as suits their purposes. So sometimes, for example, one will speak of two blind men being healed, while the other will only mention one of them. The latter is not being inaccurate but only focusing on the one that matters to him in terms of his purpose.