Drug addicts are a high risk group for triggering cost in social safety nets. The risk of driving under the influence of drugs are higher for drug addicts, there is a higher risk that parents fail their responsibility while under drugs, and as with other addictions there is an increase in risk for failing to pay rent and having enough money to pay for food. Drug addicts are also more likely to get sick and needing health care (relevant for countries where the government guaranties health care).
Since the government is expected to step in and pay for the social safety net, it then make sense that they implement laws to manage the risk and reduce costs. One way to do so is to make drugs illegal, especially those direct associated with risks that increase government costs.
If the government did not have any responsibility to supply a social safety net then there would be no need to have those laws.