Besides the inherent issue of non medically-trained people coercively prescribing medication for behavioural modification, there's the fact that drug court judges tend to disfavour opioid maintenance therapy and value abstinence from drug use over everything else; which severely increases the risk of fatal overdoses and other bad outcomes. Abstinence-only treatment does not work well for opioid addiction (http://projects.huffingtonpost.com/dying-to-be-free-heroin-t...), and coercive abstinence-only treatment doesn't work well either.
Drug rehab in US is a fucked up industry where degradation, isolation, and humiliation are commonplace and are seen as best practice, and this is the case because, well, their "patients" are literally captive -- it's either that or literal jail.