I have no idea why they’d do this either - other than “residency trumps nationality”. Playing to the “greater EU scheme” that would like to see all national interests abolished.
Remember that Scottish politics seem to be mostly socialist.
If the vote outcome is close enough that the foreigners decide, will the people accept its legitimacy?