It wasn't that they were so smart, but they were warned not to return to Herod. See the previous sentence, which is from Matthew?
It is the fact that "warned in a dream not to return to Herod, they departed to their own country by another way" (Matthew 2:12).
that wasn’t what I asked, but thanks.