From The Naked Bible:
He was instantly reminded of verses like Hosea 11:1 and the way that the messiah and the nation were identified with each other in his Bible elsewhere (the OT). Seeing the points of analogy, was led by the Spirit to note the connection in his gospel. There’s no need to view Hosea 11:1 as a prophecy that pointed to Jesus. Rather, a gospel writer saw an analogy and interpreted that analogy as something God intended to be made clear once messiah had come. We could consider it typology or a simple analogy. Either way, it made sense to Matthew and, I think, it isn’t hard for us now to see the sense of it. It’s not magic
I think this is a healthy explanation of the matter… :-)