Banks that do not charge an ATM fee can still make money through their primary operations of lending at an interest rate higher than the cost of the funds. This is generally done through lending the money that is deposited with the bank by its customers, or the money that the bank has on hand from its investments.
Deposits are in the forms of checking and savings accounts. In order to attract depositors, banks pay a small amount of interest on these deposits. By law, the bank only needs to keep a percentage of the deposits on-hand for withdrawal by customers; the rest of the funds are available for the banks to make loans. These loans have an interest rate attached that is higher than the rate paid to the depositors for the money. The difference between the rates is known as the spread and represents the profit earned on the loans.
Banks also make investments that generate income outside of loans. Commercial banks often invest heavily in securities or bonds using depositor money. As with loans, as long as the return on these investments is higher than the interest paid for the funds, then the bank makes money from the spread.