Many times they don't. It's usually something like Instagram where they give out a product for free in hopes that piles of people will start using it, and they'll "figure out something later". Worked out great for Google and Instagram, not so great for 999,999 other startups who tried it.
I always thought if you have a product that works but is free , you can commditize it by selling your infrastructure as a service ( paid API , hosting , etc ... ).
For instance , instragram could sell a way to make instragram clones in the cloud, like wordpress has a free blog script and sells blog hosting for that script, you get my point. Once you understand a domain and develop an app for that , should be easy to sell your app infrastructure as a service for thirdparty apps.
Personally, I like the idea, but it's tough.