You are not being ordered into religious rehab--you are being ordered into drug rehab, which is a commopn order and well within the court's power. It is not the court's fault that you live in a place where the only rehab providers are religious. So this is legal, because you are not being ordered into a religious program: you are being ordered to do something nonreligious, but unfortunately, you live in a place with limited options.