It's happened throughout star trek where someone is convicted of a crime on another planet, the crew do not agree with the judgement and then mount a rescue of the accused.
Star Trek 6
TNG "Justice"
ENT "Detained"
Voyager "The Chute"
Voyager "Random Thoughts"
TNG "The Outcast"
When is it the correct and not correct to escape the justice of other planets?
Star Trek 6
FEDERATION PRESIDENT: You cannot possibly believe that James Kirk assassinated the Chancellor of the High Council.
NANCLUS: Mister President, I don't know what to believe.
KLINGON AMBASSADOR: I am waiting for your answer, sir.
FEDERATION PRESIDENT: This President is not above the law.
SECRETARY (on intercom): Mister President, Starfleet Command is here from San Francisco.
FEDERATION PRESIDENT: Send them in.
C in C: Mister President.
CARTWRIGHT: Mister President.
FEDERATION PRESIDENT: Bill, ...Admiral Cartwright, Please, please sit down.
CARTWRIGHT: Mister President we cannot allow Federation citizens to be abducted.
FEDERATION PRESIDENT: Yes, yes Admiral, but I am constrained to observe Interstellar Law.
TNG "Justice"
PICARD: I understand. Perhaps your system of law and punishment is better than any system we once had. But we do now have a law I must obey. And part of it says I must protect my people from harm.
LIATOR: We did not ask you to come here.
RIKER: Which has to do with another law that we must obey.
PICARD: We are all sworn not to interfere with other lives in the galaxy. If I save this boy, I break that law.
ENT "Detained"
T'POL: The hearing's in three days.
TUCKER: And what if they're found guilty, sentenced to thirty years in prison?
T'POL: That's unlikely. If you want to explore alien cultures you'll need to learn to respect their laws. If Captain Archer were here, I'm sure he'd agree. If you'd like, I'll contact the Vulcan High Command. They might be willing to send an arbitrator.
Voyager "The Chute"
PIRI: Our brigade found out where the maximum security detention facility is located.
VEL: My sister has quite a vivid imagination.
PIRI: With this ship, you can attack the prison and get your people out.
JANEWAY: I'm sorry. That's not how we do things where I come from.
...
JANEWAY: We've captured the ship and crew responsible for the bombing at the Laktivia canteen.
LIRIA [on viewscreen]: I see.
JANEWAY: I'm prepared to trade them for the immediate and unconditional release of Lieutenant Paris and Ensign Kim.
LIRIA [on viewscreen]: Your crewmen have already been tried and convicted.
JANEWAY: Are you saying those convictions can't be reversed? No matter what new evidence is brought to light?
LIRIA [on viewscreen]: You are correct.
JANEWAY: That is an outrageous policy.
LIRIA [on viewscreen]: I assure you, it has proved to be a most effective deterrent. Good day, Captain.
Voyager "Random Thoughts"
PARIS: While Tuvok and the captain are reviewing the evidence, B'Elanna's sitting in a Mari jail cell waiting for some sort of lobotomy. We can't let that happen.
CHAKOTAY: What did you have in mind?
PARIS: Break her out.
CHAKOTAY: And risk an all-out confrontation with the Mari?
PARIS: They're a bunch of pacifists. They're no match for us.
CHAKOTAY: You're probably right. But before we start resorting to extreme measures, don't you think we should give the captain a chance to find a legal solution?
PARIS: By the time that happens, it may be too late.
CHAKOTAY: I'll tell you what. Why don't you come up with a rescue plan, one that minimises the possibility of violence, and I'll review it.
PARIS: You're just trying to keep me busy, aren't you?
CHAKOTAY: Can you blame me?
PARIS: I'm serious about this, Chakotay.
CHAKOTAY: So am I. If your plan is sound and the captain doesn't have any luck on her end, I'll recommend we attempt the rescue.
PARIS: Thanks. I'll get right on it.
TNG "The Outcast"
RIKER: I can't just leave her there. They'll give her these psychotectic treatments. I don't know what to do.
PICARD: Well, I could talk to Noor. Perhaps there's a way to work something out.
RIKER: Sir, their minds are set. They don't want to hear another alternative.
PICARD: Then I'm not sure that there's much that we can do.
RIKER: There has to be. My relationship with Soren is not trivial. She's very important to me. It's my fault that this happened. I have to help her.
PICARD: Will, if you've come here for sanction to take matters into your own hands, I can't give it to you.
RIKER: I know that, but I have to do something.
PICARD: Interfering in the internal matters of the J'naii is prohibited by the Prime Directive.
RIKER: I'm aware of that.
PICARD: If you violate it, you may jeopardising your career. Starfleet doesn't take these matters lightly, Will. I can't defend you if you go too far. Do you understand that?
RIKER: You've made yourself very clear, sir.
PICARD: Don't risk everything you've worked for.
RIKER: Thank you. May I be excused now?
When is it the correct and not correct to escape the justice of other planets?