It has nothing to do with intelligence. It is a “built-in” sense they have.
That is how birds migrate when the season changes. They don’t think about it.
Ants build “mega cities” underground without having a “blueprint” for it:
Also see the end of the post “How Character (Gati) Leads to Bhava and Jāti“