The Magi visiting the Messiah is where you realize that Matthew is not a real story but a fable. People do things because the story dictates that they do it.
God uses a star to guide the Magi, a star which curiously no one else responds to, yet rather than directing them directly to Bethlehem it instead diverts them to Jerusalem and then disappears for… reasons. Jerusalem really isn’t a good place to leave the Magi without a guide because Herod, who wants to kill the Messiah, is there. Fortunately for Herod he hears about the Magi who are wandering around asking for the Messiah, and so brings them in to question them.
The Magi seem oblivious to the danger to either themselves or the Messiah of discussing the new born king of the Jews with the current king of Judea, and so are quite happy to have a chinwag. Herod grills them to find out when the star appeared and they cough up with the answer, which gives him a pretty good estimate for when the Messiah was born. Herod forms a cunning plan – he’ll direct the Magi to Bethlehem and after they find the child he’ll have them report back to him about it.
Herod should get out of the nefarious evildoer business. He could have had assassins follow the Magi the whole 10 kilometers to Bethlehem, or he could have had assassins disguised as guides travel with them the whole 10 kilometers to Bethlehem, or when the star reappeared to guide the Magi again he could have just followed it the whole 10 kilometers to Bethlehem. Or, since he already knew the age of the Messiah, and since he was prepared to kill all the infant male children anyway, he could have gone the whole 10 kilometers straight to Bethlehem and killed them all right then. Pretty much any proactive plan would have been better than the one he decided upon.
The kicker is Matthew 2: 12 which is, “And having been warned in a dream not to go back to Herod, they [the Magi] returned to their country by another route.” So God could not only have sent the Magi directly to the right house (not guest house with manger in this version) in Bethlehem, but he could also have warned the Magi by dream of Herod’s duplicity just in case they should run into him or his men, since they were just 10 kilometers up the road. Just as when he decided to inform Joseph after the fact about impregnating Mary, once again God seems to be very unconcerned about the harm his actions have on people.
If the actions of the characters make any sense to you then you’ve got a big future in writing for daytime soap operas. And before you bring up prophecy as the why the people did the things they did, have a very careful think about who created those prophecies, or what it means to freewill to have people forced into actions because of it.