Drug use is a seen as a moral failing. A morally weak person is seen as someone who will be a bad employee (steal, not put in a good day's work, cheat the clock, etc.).
If I'm running a factory or warehouse and I need sober, alert workers that will not destroy merchandise with equipment and/or kill themselves or others around them, you can be damned sure I'm going to eliminate any risk of their personal time seeping into their work time.
Screening for recreational drug markers doesn't mean I'm judging their morals, but I'm zeroing out my risk factors.
Do you screen for cigarettes and alcohol use as well? Smoke breaks take up a lot of time, and someone with a hung over or slight buzz can be a safety issue.
What I've seen is that most companies don't care about those. They only care about illegal drugs. Even legal prescriptions that could have nasty effects are not judged harshly.
In short, there are more defensible reasons to drug test than what I listed, but they don't show up often in practice.
Does it make sense? Often it makes none at all.