It can and does happen that way sometimes. I'd strongly suspect it requires a combination of personal desire for longterm change and some form of significant break whether that be in terms of inpatient detox and/or rehab, taking yourself away from your usual setting for (at least) a couple weeks or maybe even locking yourself in for a fortnight with enough supplies for there to be no need to go out and deal with the world for a while.
The personal desire is obviously the most vital aspect - and I'd agree nobody will ever quit without that being in place - but I do believe a change of scene and some time away from the people and places strongly associated with the daily addict routine really helps too. Is the combination that (more or less) worked to deal with my own reasonably lengthy (12 years) and reasonably heavy (fuckloads) period of heroin and crack addiction. My final binge lasted approximately three weeks and often ran at several hundred pounds a day. Looking at that alone it perhaps wouldn't seem like I was truly ready to quit - and I wasn't entirely sure I was either in all honesty having been through so many cycles of detox and relapse. I've used heroin and crack a handful of times since - all one-off uses.
I do still recognise addict patterns of thinking and behaviour in myself though so am hoping to gain an inpatient rehab placement before the end of the year as I feel it will help to shake off the fag end of a quarter century or so of generalised addiction issues (yes I quit heroin and crack but oranges are not the only fruit as it were...). Unfortunately there's likely to be quite a wait as I believe my local health authority only funds four placements per year and, also, I've ruled out 12 Step-based programmes. This mostly leaves SMART Recovery-based programmes but there are considerably less of them unfortunately (which is ridiculous as it is at least an evidence not faith-based system). Am attendiing the local SMART meetings in the meantime and it feels like I may be absorbing things osmotically if not really very actively so far.
Hmm... no, I'm not sure there was enough point to justify length of ramble either but such is the way of ramblings I suppose.