The fee to withdraw cash from an ATM using your credit card (as opposed to your debit card) is akin to the merchant fees paid by any business that accepts your credit card as payment. These fees range from around 2.75% of the transaction to upwards of 5%, and are charged to the merchant.
The fees are split among the various vendors that provide the infrastructure to conduct the credit card transaction — resulting in the merchant receiving the money and the charge on your credit account. These fees are used by each vendor to cover their costs and, ultimately, generate a profit. (Note: Most vendors in the value chain DO NOT receive any revenue from any interest you may pay on your outstanding balance.)
Therefore, when you withdraw cash from an ATM, you are paying the merchant fees instead of whatever merchant you are purchasing goods/services from with the cash withdrawn.