According to the law he should have been circumcised on the eight day after birth but was he in Egypt at that time?
In Luke 2:21 Jesus was indeed circumcised when he was 8 days old.
In the Gospel of Matthew there is no definitive time frame given for the time between the birth of Jesus and the flight to Egypt. The slaughter of the innocents targeted children up to 2 years of age which suggests that the visit of the Magi did not coincide with the immediate birth of Jesus. And even if it had, the Gospel does not tell us how long after the birth they arrived or how long they stayed.