They're often solving problems that affect large numbers of developers (initially, inside their company). And, because of the scale of a company like Facebook, they can afford to work full time on these projects.
They then open source them because there's no strategic value to keeping them private, and significant upside to building a community around them (and not undermining that).
I'd argue that some of the best open source projects come from large companies - due to the sheer number of developer hours they can throw at them. Small dev shops can't afford it, there are very few OSS foundations, and there just aren't that many people (relatively) that can devote enough time on the side to compete.