When there's a global structure that has decided that those countries are not worth doing business with over the actions of their government.
That's the whole point...
You seem to be implying a value judgement I'm not making. I'm not making some random condemnation of Russia/Iran/Whoever, or extolling the virtues of western countries - I'm telling you the point of sanctioning those countries is that it's a path towards adjusting behavior by removing consent of those governed.
If the Russian/Iranian/Whoever people are happy, content, well-fed, and have easy access to luxury items... what the hell is their incentive to change how their government is acting on the international stage?
The sanctions serve to show those people providing consent that the rest of the group of nations they are interacting with are not happy.
It's a feedback mechanism that is not: "hey - we're going to kill you now". Which Western nations are using 1) because it's less expensive in terms of both capital and bodies. 2) because it's arguably more humane. 3) Because nuclear weapons have made countries averse to full war.
There's no value judgement about whether the sanctions are good or bad, or some prescriptive judgement that the west is better. It's just the clear intent of the sanctions is to make life harder for the citizenry without having to kill them.
Whether the countries making the sanctions are moral or not (in my opinion, your opinion, or that of anyone else) has fuck all to do with the functional manner in which they are being used.
Sanctions are a tool, whether that tool is being used justly has zero relation to how the tool itself functions.