* Black market drugs can have widely varying contents and potencies (rat poison and fentanyl).
* Tolerance changes have already been mentioned.
* Taking drugs in a consistent place and/or circumstances causes the body to prepare for consumption (like Pavlov's dogs salivating at the bell). Unfamiliar situations can catch the body off guard.
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.
Whereas with illegal opiates it's often from a difference in purity from one purchase to the next. This is where a regulated drug market would alleviate that issue 100%.