All from an Australian perspective anyway.
I think part of it is based on the perception that those icky poor people just sit around all day ripping bongs or everyone on welfare is a bogan.
As far as i know, it's fairly hard to just stay on welfare for no good reason and sit around all day watching TV. They try make you work and they progressively cut down your money over time if you don't (as far as i know).
It also must be remembered that whilst living on welfare is indeed
living in the sense you can eat, its far from living the
good life. It's meant to be deliberately unpleasant, it's enough to keep you alive and reasonably healthy but it's not enough to live a proper life off, like enjoying the rare pleasure like going to a restaurant or seeing a movie.
So, i think a lot of this springs from some very warped idea that we have
welfare queens (usually tinged with racial or class undertones as well) living it up off our money. We don't. If you're spending your money on any significant amount of drugs, then, you're probably even skimping on things like food, you have bigger problems than mismanaged spending then.
Most of us receive government money in one way or another. A lot of families get family tax benefits, people get the baby bonus, a lot of families with school aged children got some kind of educational bonus from the government. I'm not convinced why, if you say we shouldn't drug test these people, why we should drug test people on the dole, rather than the perception that everyone who is poor is an icky, deadbeat, non-motivated loser. Not to mention, under this regime, they can still spend it on perfectly legal drugs if they like but i'm sure it's patriotic to support the goon industry after-all.
I've also seen some arguments that suggest it would cost more to enforce this (not to mention the liberty cost) than you would reap by totally cutting drug users off from welfare, which, i don't think is consistent with values in a society like Australia. I'm not happy they're using drugs, they need help but doesn't mean we should cut them off from welfare and let them die on the street either.