Here’s a theory that was raised in a book by Neal Stephenson:
This goes back to the debate between moral absolutism and moral relativism. In a society that agrees on moral absolutes, the issues you raise do not arise. People clearly see that doing X in one context is wrong, whilst doing X in another context is OK, or even admirable.
However, in our postmodern morally relativistic world, there is no absolute to match an action or behavior against. Therefore, the only yardstick you have to measure against is “hypocrisy”.
So, the in the former example, you err when you violate the absolute; in the latter example, you err only if you are inconsistent.
So, it logically follows that if doing X is bad in any context, then doing X is wrong in ALL contexts.
Hope that helps.