In an ideal world (well, my ideal world), these fees would be called out so that you, the customer, could choose not to pay them. You might see, "if I pay cash this $100 product will cost $100 but if pay with my platinum card it's $105. I can save $5 by paying cash".
Mastercard and Visa forbid this for two reasons: (1) they don't want you choose the cheaper cash option (2) they don't want a competitor to be able to offer a lower fee. In the example above, they charge $5 but a competitor could charge $1. You'd might pick the cheaper option but you're unaware of it since they forbid the merchant from offering.
They can only do this because they effectively have a duopoly on the market. Don't play by their rules, lose 99% of your customers. Various governments try to fix this. The cynical reason it hasn't been fixes is they pay off politicians to make sure it doesn't get fixed.
The govt both sides really want the economy here to eventually move to electronic so it can be tracked hard - however it was obvious the banks along with the $$$$$ credit card companies were making making a killing even at 2.5 % of all retail purchases ... so it was better to encourage merchants adopting close to free services like eftpos again which is about 0.2% max of a transaction.
Caveat - Of course some big retail stores can negotiate down the transactional percentage they pay in fee to Visa, Mastercard or Amex ... though I don't think any here got anywhere near as good a deal as Stripe. [1]
[1] https://stripe.com/au/resources/more/eftpos-fees-and-charges...
> where Visa and Mastercard debit is about 0.5%, and many credit cards are an average of 0.9% or more.