The Prince of Egypt: Subverted. Seti expresses regret in regards to ordering his soldiers to slaughter the Hebrew newborns. However, his following remark makes his real feelings about the matter even clearer.
Aladdin: Aladdin justified his stealing by only taking what he needed to survive and nothing more. On the one occasion where he did take more than he needed, he was devastated to see how much he hurt someone and returned the money.
Queen Elsa does this in Frozen when she shuts herself out in order to protect her sister, Anna, from her powers that almost killed her.
Bad Cop has to justify doing this in The LEGO Movie, since it's his and Good Cop's neck on the line if he doesn't Kragle his own parents as punishment for failing to capture the Special. Both sides were clearly distressed to hear that they had to do this to their own parents; but Bad Cop did it because he knew the harsh consequences that would otherwise happen if they didn't obey. Unfortunately, this becomes the case when Good Cop can't bring himself to do it, winning out his other side and having his own face wiped clean off as a result.
Isle of Dogs: One of the dogs on Trash Island, Gondo, says that he and his pack have a choice: either eat a comatose dog to survive or starve to death. They end up eating said comatose dog, and even though Gondo says that they did what they had to in order to survive, he still feels ashamed of doing it.
Any Scifi horror movie where people who are infected by The Virus have to be killed or risk having them turn on the uninfected cast. Closely related to most zombie and werewolf movies. Contrast What Happened to Mommy?.
Inverted in the first Resident Evil movie. The infectee even receives the cure... and still turns into a zombie at THE WORST POSSIBLE MOMENT.
A light-hearted version in Running Scared (1986). The two cop heroes are in a hostage situation with a gunman who doesn't have any pants (long story). He orders them to take off their pants and give them to him so (a) he'll have a pair and (b) it will be harder for them to follow him. They do so. Later in the station house they're asked how they could give up their pants, and one of them says "We did what we had to do."
Stella: What did you do to yourself? Eben: What I had to do.
Played straight to the letter by Ozymandias of Watchmen who not only goes to ridiculous lengths to dupe the world into think they're under attack (and killing millions in the process), he also kills his beloved Bubastis in a vain attempt to kill Dr. Manhattan.
"A world at peace. There had to be sacrifice."
Featured prominently in the second of many speeches in V for Vendetta.
Lewis Protero: We did what we had to do. Islington. Enfield. I was there, I saw it all. Immigrants, Muslims, homosexuals, terrorists. Disease-ridden degenerates. They had to go.
In a more comical direction, the entire premise of John Waters' Serial Mom is a suburban woman who feels morally justified in offing people for bad manners, not recycling and fashion faux pas, like Patricia Hearst's white shoes after Labor Day. Though funny, John Waters has stated that he feels very strongly about all these grievances (especially the last).
Carriers. In a world where there's an infectious virus that kills people, pretty much everyone is forced to kill people who are infected but not yet dead. On some occasions our 'heroes' kill some non-infected people when they refused to give up gas in their car. They needed this gas to survive.
Some latter-day reviews of this film point out that there is actually little plot justification for Bond killing this particular man, other than continuing to establish the "licence to kill" aspect of 007 in a way Ian Fleming never did in his books. (According to Word of God this is why Bond is shown murdering Professor Dent earlier in the film, again an event never depicted by Fleming.)
In the The Dark Knight Rises, this is done by Jim Gordon when he is called out by John Blake over hiding the Two-Face murders by blaming it on Batman. An interesting take, however, as this is suggested by Batman himself, he is never seen as a villain or a Knight Templar, and since the audience has seen the exact decision process behind it, is does seem like the best idea at that point in time.
In Dangerous Beauty, this is Veronica Franco's justification for why she became a courtesan: "I repent there was no other way open to me. I do not repent my life."
In Zombi 3D when Dr. Holder and his assistant, Norma, confront General Morton as the infector's body is burned, Morton uses this as an excuse.
Dr. Holder: Who told you to burn the body of the man infected with Death One? General Morton: ...I had to close an episode.
In Tell No One, this is how Jacques justifies helping Margot fake her death and not telling Alexandre about it; he was trying to keep Margot away from Gilbert, since she had killed Gilbert's son.
In Dracula Untold, this is Vlad III Dracula's reason for becoming a vampire, as well as his reasons for the impalings earlier in his life.
In Draft Day the Browns general manager Sonny Junior fired his dad as the head coach, because his father was at risk of dying during his stressful job. Firing him would have resulted in some relaxed years. Too bad his dad died anyway.
Assassin's Creed (2016): Joseph Lynch's first scene is immediately after Mary's death and he is constantly repeating the Creed like a Survival Mantra, as if he's trying to reassure himself that he did the right thing.
In Trumbo, Edward G. Robinson says "I did what I had to do" while explaining to Trumbo why he named names to HUAC.
In Avengers: Infinity War, Thanos uses this to justify sacrificing Gamora for the Soul Stone, and it's become a Berserk Button for Peter Quill since his father Ego used it, stated below:
Peter Quill: Asshole! Tell me you didn't do it!
Thanos: I... had... to...
Peter Quill: No, you didn't.
In Guardians of the Galaxy Vol. 2, Ego says these exact words when explaining to Peter Quill why he left Meredith, Peter's mother, if Ego loved her so much:
Ego: I returned to Earth to see her three times. And I knew if I returned a fourth, I'd never leave. The Expansion, the reason for my very existence, would be over. So I did what I had to do. But... it broke my heart to put that tumor in her head.