Consider the following passage in Matthew 2:14-15:
“When he arose, he took the young Child and His mother by night and departed for Egypt, and was there until the death of Herod, that it might be fulfilled which was spoken by the Lord through the prophet, saying, “Out of Egypt I called My Son.”” [1]
This is a quotation from Hosea 11:1. The context of this verse in Hosea is very clearly speaking of Israel. It seems at first glance that this is a case where the writer ignored the primary meaning of the Old Testament passage and provided a second meaning not understood by the original writer.
However, this idea of God calling the Messiah out of Egypt is indeed found in the Old Testament. In Numbers 23 Balaam presents his second prophecy and then in Numbers 24 his third. There are striking parallels between these two prophecies, with the distinct difference that the second prophecy is in the plural and the third is the singular. Numbers 23:22 says “God brings them out of Egypt”, but Numbers 24:8 says “God brings him out of Egypt” [1].
This is dealt with in more detail on pg 107-109 of [2]. In the passage in Numbers 23-24 Israel is established as a type of Christ, the Messiah, with the clear detail set out of both Israel and Christ being brought out of Egypt.
Why then does Matthew not reference Numbers 24:8? One reason may be that he was trying to emphasize the relationship between the Father and Son [2]. If Israel is a type of Christ, and specifically in the journey out of Egypt as seen in Numbers 23-24, then a verse clearly regarding Israel’s journey from Egypt may be applied to Christ typically while interpreting literally.
The literal interpretation method is therefore seen as quite plausible in this context. An allegorical interpretation method is also possible.
[1] New King James Version, 1982, Thomas Nelson, Inc.
[2] The Moody Handbook of Messianic Prophecy, 2019, The Moody Bible Institute of Chicago, Chicago , IL.