At the end of the seven days following childbirth, the male child was to be circumcised (Lev. 12:3), and Luke 2:21 states that Jesus was circumcised on the 8th day. However, the mother's impurity did not end with the seven days, because she had to continue her purification for an additional 33 days: "She [the mother] shall then continue in the blood of her purification thirty-three days. She shall not touch any hallowed thing, nor come into the sanctuary until the days of her purification are fulfilled" (Lev. 12:4). At the end of her complete purification (a total of 40 days), the mother had to "bring to the priest a lamb of the first year and a young pigeon or a turtledove as a sin offering" (v:6), which were offered in sacrifice to Yahweh. However, if she could not afford to offer a lamb, she could bring "two turtledoves or two young pigeons" (v:8).
Luke 2:22-24 presents Mary as making the sacrifice of poverty (a pair of turtledoves or two young pigeons) "when the days of her purification according to the law of Moses were fulfilled." Hence, this would mean that Joseph and Mary were still in the region of Bethlehem and Jerusalem 40 days after the birth of Jesus, so we can reasonably wonder why Matthew's Herod was taking so much time to rid his kingdom of the threat that Jesus represented to him. As someone else pointed out, Luke 2:39 says, "And when they had accomplished all things that were according to the law of the Lord, they returned into Galilee to their own city Nazareth." It is certainly unreasonable to think that Luke was aware of a trip into Egypt that the "holy family" took before going to Galilee.
F. Till