Facebook in particular seems to wildly overinvest in internal tools, and if you ask them why they don't use external stuff they tell you it's because "it doesn't scale". We get things like Phabricator and HHVM out of it, but they could've just not written those, and I'm pretty sure their business would be fine.
They do it because it gets them promoted, and because FB and Google rely on hiring every engineer ever and giving them make-work so they won't leave and start a competitor.