This wasn't originally the case. Passing on the fee was for a long time against most merchant agreements. Which makes sense from the credit card company's point of view: they don't want shoppers to have any reason not to whip out the card.
The big change came in January 2013 after a big court judgment. Adding fees, though, is still illegal in some states: https://www.creditcards.com/credit-card-news/business-surcha...