Varying potency. Dealers putting in fentanyl or stronger opiates to intentionally cause an overdose as marketing hype for their product (very common). Misjudging the dose of a known product. Tolerance. Using too much after some time stopped. Mixing opiates with other substances. I'm sure there are many more.
If you're using street opiates, it's going to happen at some point, guaranteed. I've yet to meet an opiate addict who has never overdosed and I doubt I ever will. Sticking to prescription opiates helps, but even then people overdose often.