This is what the Scotsman actually has to say on the matter:
"It has been claimed that if someone knocks on your door in Scotland and needs to use the toilet, you are bound by law to let them enter.
The Scottish Law Commission however said there was no evidence to support this and that the myth may have grown around local custom and point to Scottish people’s “strong sense of hospitality”.
It appears as though this ‘law’ was little more than a tradition, or polite custom. That said, trespassing was once legal in Scotland due to a law that allowed free passage through people’s land and it’s not entirely beyond the realms of possibility that the custom was borne from this. Initially passed to allow people to cross large areas of land belonging to neighbouring clans (which gives you an idea of the age of this law), it is now used today by hikers."
https://www.scotsman.com/news/uk-news/scottish-law-myths-explored-and-debunked-2463903