In the case of Wells Fargo, I believe that free trading is linked to your overall banking relationship with the firm. So if you have a checking account with a balance of $X, or a total relationship with the bank ("relationship" is usually defined as loan balances + deposit balances) over a certain amount, they give you a plum like free stock trades.
The theory behind this approach is that banks want to be a one-stop shop for you. The idea is that they can market the banks products to you over a period of years (lowering customer acquisition cost) and offer you a level of convenience that allows them to charge a premium for services. For example, many people will pay a rate or fee premium on a mortgage or car loan so that they can do all of their business in one place.
In other cases, free trading is linked to marketing campaigns by funds. Charles Schwab started this with the "no transaction fee" mutual fund store many years ago -- transaction fees are actually paid for by the mutual funds who pay for placement in the program. "Free ETF trade" programs are similar.