It’s not something that was decided by one ancestor and then inherited by everyone else.
It was something that certain birds had a tendency to prefer. Those birds thrived and reproduced at a higher rate, while birds without that preference presumably found less suitable homes.
It’s just natural selection and normal genetic variance. Some offspring every year will be born with slightly difference preferences due to the influence of various genetic differences. Some of those differences will be more beneficial for finding a good “home”, others less so.
There was a recent report of a very confused penguin showing up on a beach far from their normal habitat. Apparently this happens every once in a while. Those cases did not win the genetic lottery (though hopefully it made it back to a more suitable climate)
I would add that there can be many local maxima, so it isnt always about finding less suitable homes. Birds of the same species can have different homes.
I believe Salmon use a similar mechanism, but it might be supplemented with chemical signatures. For Salmon, it’s possible that they genetically inherit the capability but learn the location at birth.