Two points that may at be part of the reason why major stations seem to collect a lot of the less desirable examples of humanity, for want of a better word, one of which applies mainly to Germany. In Germany the Ladenschlussgesetz means that the station area is often the only area in town with shops, light, warmth and people milling about, so it attracts the lonely, both good and bad, out of hours. (I know that the gesetz has been eased, but it has left a legacy.)
Also many areas around major stations developed in the late nineteenth century to serve the needs of travellers, but due the nature of such businesses became rundown, something that was exacerbated by World War II. Even if they have been redeveloped in recent years, they tend to be full of businesses that are either trying to relieve the traveller of his money or close at 17.30, so the only people who live there are those who don’t have much choice. (Smaller towns are different as they often see the square outside the station as the welcoming face of the town to visitors.)
With regard to the difference between airports and railway stations, am I right in thinking that airports often own the land for a considerable distance around the terminal building, whereas a the railway usually owns little but the station building? Therefore the airport on its own can take action to move undesirables well away, whereas the railway can only move them a few yards.
I used to live a street away from Copenhagen Central on the edge of the red light district (actually more in it as my lodging was a cross between a doss house and a knocking shop) in an area that really was the sump of Scandinavia. The station was not too bad as there was a police station in it and a quietly proactive attitude to trouble: they did not want visitors, or anyone else, annoyed and if you did they were in place to rapidly make your day thoroughly unenjoyable. As it was often busy, you still needed to keep your wits around, but it wasn’t threatening. That said, Copenhagen is generally not particularly bad, although there are odd bad bits. (The only place I felt seriously threatened was Oslo, where a short-cut resulted in my running like the clappers to a well-lit area to avoid being mugged.)
As said above and I have said before, your best defence is to look as though you know what you are doing and where you are going. Don’t wander vaguely along with a tourist map held in front of you.