My understanding is that loitering laws are much older than that - the first versions of these laws seems to date to 1342 [1].
IMO what all these laws have in common is that they're designed to allow the police to legally ask questions to people (or straight up remove them) who look suspicious but haven't committed any crime. Why would anyone want to remove people who haven't done anything wrong is a more nuanced question that I'm not qualified to properly answer.
Have an unmarked "free candy" type van park across your street from your house day in and day out, moving with just enough regularity to avoid parking too long, and you might begin to understand why "look suspicious but haven't committed any crime" starts to weird people out.
There's an inherent tension between protecting public spaces and protecting vulnerable but disruptive people.
Your link refers to an article which is very American and very 2018. Lots of large font size headings about race and sexuality and gender. I don't think it's a productive take on how to manage the tension. Racially homogenous societies still need to decide how to handle people who try to sleep at train stations and yell at the commuters.
Sleeping at train stations is fine (as is sleeping on trains), and yelling at commuters is disruptive / antisocial behaviour. (I don't like the word "antisocial" in laws, because it's too open to interpretation, and then you have a load of case law defining what precisely "antisocial" means, known only to legal experts, leaving everyone else ignorant of the law.) It seems to me that additional rules against loitering are not useful for the situation you described.
Why is sleeping at a train station fine? (Unless you're talking about infrequent long distance trains).
Trains are transportation infrastructure. Drivers don't have to put up with people setting up a queen bed in the middle of their lane on the highway. If a country doesn't protect its public transport infrastructure, then the rich and the middle class stop taking the train, the poor have to put up with things, and the mentally ill get an overpriced and noisy mobile homeless shelter. One that costs more and helps less than crisis accommodation.