Sanctions hurt the people, legislation hurts the companies. When you actually want something, you use legislation. When you want to virtue signal and torture people, you sanction. Not that it works - I'm pretty sure sanctions lead to extremist views in the opposite direction than what was planned.
For example, country Monkeyland does a bad thing that they believe is good (ofc otherwise they wouldn't do it). You then sanction them, which hurts the poor (no money, less money due to sanctions), ill (no meds), and inconveniences everyone else and shows them that the rest of the world really is "evil", like their own government says.
Legislation gives an illusion of choice, and in these cases usually doesnt lead to pain and hurt.