It's not just real estate. I'm not sure about today, but in the 2000s when I worked at Intel, they owned their own jet planes. They had so many employees flying between certain cities they had locations in, that it was more cost-effective for them to operate their own mini-airline.
Outsourcing stuff always costs more, because you have to pay for the profit of the company you're outsourcing to. It's worth it when it's something you don't do that much of, or aren't very good at, but if you do a lot of it, it's worth it to do it yourself.
For an extreme example, think about printing: is it worth it to outsource all your computer printing needs to a specialized printing company? Or should you just buy a laser printer for $100-500 and do it yourself? It doesn't take very much printing for it to be a massive waste to pay someone else to print stuff for you.
Outsourcing stuff always costs more, because you have to pay for the profit of the company you're outsourcing to. It's worth it when it's something you don't do that much of, or aren't very good at, but if you do a lot of it, it's worth it to do it yourself.
For an extreme example, think about printing: is it worth it to outsource all your computer printing needs to a specialized printing company? Or should you just buy a laser printer for $100-500 and do it yourself? It doesn't take very much printing for it to be a massive waste to pay someone else to print stuff for you.