What's the name of the fallacy where someone appeals to different circumstances that don't currently apply in order to justify something?
Here is the fallacy I'm describing:
Someone defends their own actions, or someone else's actions, as acceptable/justified or necessary, on the basis that those actions might be necessary or justified in certain circumstances, referencing other individuals or circumstances for which it might be necessary or justified, despite their own circumstances/the circumstances in question not having the same elements that would require it or justify it.
For example, someone defends the actions of someone who murdered another person unnecessarily because they disliked them (e.g.), using the argument that there might be people who need to kill in self-defense or in a survival situation for whom it might be justified, despite that not applying to the situation in question.
I'll attempt to write the form of the fallacy here:
X is justified in Y case.
Someone does X in Z case.
X is justified in Z case because X would be justified in Y case.
It's a fallacy because:
What is true of Y case doesn't necessarily apply to Z case; the elements/circumstances of Y case that would make X justified may not be present in Z case, and therefore even if X is justified in Y case it wouldn't automatically be justified in Z case as a consequence.
It's not necessarily a fallacy, because the argument that Y and Z are equivalent or sufficiently similar to both justify X is a valid argument.
The argument that they're similar might be an example of a false equivalency however, which is an informal fallacy, and so depends on the circumstances of the argument, since it's not de facto invalid to draw an equivalence between two things.
A simple fine is a just punishment for littering. Someone threw a bag of trash out of their car on the highway (illegal dumping, not littering). Because a fine is justified for littering, and illegal dumping is similar to littering, a fine is justified for illegal dumping.
The equivalence between littering and dumping isn't unreasonable.
A simple fine is a just punishment for littering. Someone burnt down an orphanage (arson and heinous murder, not littering). Because a fine is justified for littering, and arson and murder are also crimes, a fine is justified for them as well.
The equivalence between littering and murder is weak at best, and most would find it unconvincing that we should treat them the same.
(There's a fun related problem where the equivalence is bad, but both conclusions are actually agreeable. It can lead to some weird arguments. "Hitler deserved to be removed from power. Hitler was a man. Stalin was also a man, and therefore deserved to be removed from power")
The argument is that Y and Z are similar enough to extend Y => X to Z => X. This might be valid if Y and Z are indeed the same in all aspects that matter, if not then I'd say it's a False equivalence.
It is not known whether Z is actually Y or not, but it's assumed to be true to extend Y => X to Z => X. In that case it should be Appeal to probably.
I'm not sure it's a specifically named one, but then again there are dozens, and they're hard to keep straight. In general it is (attempted) rationalization, hand-waving, and kinda... just a bad argument. It does not actually explain why that specific murder was "necessary" - only that it could've been.
The intent is to rationalize, but it might not get close enough to a real argument to pin down to a specific (in)formal fallacy.
It might be similar to a Motte and Bailey Fallacy. Though that one is more focused on distinct but related definitions than it is for distinct but related situations. Not the exact one that you are looking for, but the related concepts might be a path towards an answer.