Sanctions work by preventing this transaction from happening, which means both the buyer and the seller are worse off compared to when they are allowed to trade.
The key point here is that although both the buyer and the seller are worse off, one party may be disproportionately impacted. This is the case with the Russian sanctions, as Western companies can usually find other markets (although less lucrative) but Russia is now having serious trouble sourcing certain components.
McDonald's is likely doing this for image reasons or to appease stakeholders rather than doing it to punish Russia directly, but the outcome is that Russians are slightly worse off than before.