Jeremy Pierce suggests that there should be legal loopholes to allow torture in those rare (ticking time bomb) cases where it could be morally justified. (Similarly for genocide, terrorism, and other such evils we would normally treat with a blanket ban.) I think that's a bad idea, as loopholes tend to be widened and abused, so the end result would be more legal cover for immoral torture. A better way to look at it is this: if an end is worth torturing someone for, then it's worth going to prison for. It's actually a good thing that the decision-maker burdens some of this cost, since it provides a much-needed cautionary incentive. They won't engage in illegal torture unless they really, really have to.
For similar reasons, it's important that Civil Disobedience be punished by the law, no matter how sympathetic we may be. Sometimes, right actions ought to be punished. It's unfortunate. But not as unfortunate as the alternatives (excessive torture, general lawbreaking, etc.).