Not every drug is an opioid. We have prohibition laws designed for opioids blindly applied to any (in the western context) nontraditional drug. The German law on drugs is literally called "the painkiller law", for instance.
Interestingly, in both cases the semantic shift seems to have been caused by the enactment of laws to control drugs. The legal term these days is probably "controlled substance" in English, but "narcotic" now definitely refers to many drugs that are not medically narcotic.