From The Gospel of Matthew by Curtis Mitch and Edward Sri, commenting on Matthew 2:1:
The word magi originally described members of the Median and Persian priestly caste who advised the king and interpreted dreams. The term later was used more broadly to denote those who possessed mystical knowledge as priests, astrologers, soothsayers, or sages. Their popular association with kings today may be based on Old Testament passages that recount kings bringing gifts to the royal Davidic son (Ps 72:10–11), including gifts of gold and frankincense (Isa 60:3–6). In the Jewish tradition magi would bring to mind the opponents of Daniel in Babylon, who were associated with enchanters and sorcerers and claimed to interpret dreams and signs (Dan 1:20; 2:2; 4:4; 5:7 LXX). Hence, one would not expect magi from the East to be among the first to pay homage to the Jewish messiah. This account thus sets up a theme that will be repeated throughout Matthew’s gospel: Israel’s king is welcomed by those one would least expect while Jewish leaders work against him (2:4).