Banks often offer cash to people who open savings accounts in order to drive new business. Their gain is pretty much as you think, to grow their asset base.
A survey released in 2008 by UK-based Age Concern declared that only 16% of the British population have ever switched their banks‚ while 45% of marriages now end in divorce. Yip, till death do most part.
In the US, similar analysis is pointing to a decline in people moving banks from the typical rate of 15% annually.
If people are unwilling to change banks then how much more difficult for online brokers to get customers to switch?
TD Ameritrade is offering you 30 days commission-free and some cash (0.2% - 0.4% depending on the funds you invest). Most people - especially those who use the opportunity to buy and hold - won't make much money for them, but it only takes a few more aggressive traders for them to gain overall.
For financial institutions the question is straightforward: how much must they pay you to overcome your switching cost of changing institutions? If that number is sufficiently smaller than what they feel they can make in profits on having your business then they will pay.
EDIT TO ELABORATE:
The mechanism by which any financial institution makes money by offering cash to customers is essentially one of the "law of large numbers".
If all you did is transfer in, say, $100,000, buy an ETF within the 30-day window (or any of the ongoing commission-free ones) and hold, then sell after a few years, they will probably lose money on you. I imagine they expect that on a large number of people taking advantage of this offer.
Credit card companies are no different. More than half of people pay their monthly credit balance without incurring any interest charges. They get 30 days of credit for free. Everyone else makes the company a fortune.
TD Ameritrade's fees are quite comprehensive outside of this special offer. Besides transactional commissions, their value-added services include subscription fees, administration fees, transaction fees, a few extra-special value-added services and, then, when you wish to cash out and realise your returns, an outbound transfer fee.
However, you're a captured market. Since most people won't change their online brokers any more often than they'd change their bank, TD Ameritrade will be looking to offer you all sorts of new services and take commission on all of it.
At most they spend $500-$600 to get you as a customer, or, to get you to transfer a lot more cash into their funds. And they get to keep you for how long? Ten years, maybe more? You think they might be able to sell you a few big-ticket items in the interim? Maybe interest you in some subscription service? This isn't grocery shopping. They can afford to think long-term.