Why shouldn't opiods be legal? Sure, they are bad. But so is tobacco. Most overdoses happen precisely because of unstable dosages or unexpected fentanyl.
Opioids are at the other end of the spectrum - they are highly addictive and aside from the possibility of accidental overdose, even just using them at the correct dosage carries a lot of negative health consequences. It is not clear that you get a net win for society by legalizing opioids.
Keep the supply of the substances illegal, but provide safe places - staffed with medics - where people can have their drugs tested, take the drugs in as safe a way as possible and be signposted to rehab and recovery services, including mental health services.