> But that said, why do so much for open source?
It gets them more users for their services if people make use of their open-source libraries that happen to be optimized for Google, e.g. by integrating better with Google's cloud offerings.
> Why not keep big things proprietary?
They do keep big things proprietary. If it directly makes money for Google, you're not going to see it's source code, unless you work for Google.
> Why sell Chromebooks that can be unlocked, put in dev mode, and flashed with FOSS BIOS implementations? Why allow unlocking the bootloader on Nexus and Pixel phones?
Most people don't change their OS ever, so it doesn't really matter whether bootloaders are locked or not. Even if more people did it, many of them would still install Google apps, so it would continue not to matter.
> There's lots of things they do that clearly aren't for the bottom line or just to trap you in their ecosystem (they do offer versions of basically everything for iOS as well, which makes it easier to switch to iPhone even if you are deep in the Google ecosystem).
Google is not in the phone business. Their phones are just funnels for their advertising business. If they were in the phone business, offering those indispensable apps to iOS users would decrease their ecosystem lock-in. But because they're not in the phone business, offering apps for iOS increases their ecosystem lock-in, because even going to Apple, you still stay with Google.
Nexus/Pixel phones exist only as funnels into the Android ecosystem. Android exists only as a funnel into default-installed Chrome, Gmail and Google Search. Chrome itself is a funnel for Google Search, while Gmail's purpose is to make people sign into an account for easier tracking. Then there's the general ecosystem pull of being the one-stop shop for a bunch of online services. But in the end it all boils down to ads.
Because the majority of their products are only funnels, they'll happily cooperate with competitors for some of those products, if that helps them keep people in the wider Google ecosystem. So you get Chrome for iOS, Google Search for Firefox and so on.
When a company seems to be hurting their own bottom line by giving away stuff for free, it's usually because the free stuff isn't that important to them and their real bottom line is elsewhere.