Lots of people stay here despite the costs because of the positive externalities that come with living in the bay. There are many alternatives to a highway commute (bike in the city, Caltrain, work from home) that many new grads are able to take advantage of. There's easy access to nature, culture, and for a lot of people, an extended network of family and friends that probably wouldn't be so welcoming in other places that don't have the same strains on housing.
I expect that many will move away for opportunities elsewhere before ultimately returning, but that seems to be a desire for exploration rather than dissatisfaction with quality of life. Certainly, few of the people I know are itching to leave the city for even low-density suburban living, and that's a preference that just can't be squared with many of the commenters here that rave about living on their 3 acres of land for $200k in the middle of nowhere while working remotely.
There are a lot of problems in the bay (and even more in the city) that I hope we can address, but making it out to be unlivable for young engineers (again, a very privileged class) is ridiculous. Are there better places to raise kids? Yes. Are there cheaper places to live? Yes. Are there other urban areas that provide some of the same benefits? Yes. Do I want to live anywhere else? Not right now.
Living with roommates is fun when you’re young, but nearly everyone tires of it eventually. You can also get a one or two bedroom with a partner and good salaries, but try adding a kid and that place is packed to the brim.
To counter your anecdote, I’m 30, and have been in the bay about 4 years. I believe I grew my career in the bay faster than I could have anywhere else, and am very happy to have come here.
I’m still single, so have no plans to leave, but _none_ of my friends my age looking to start families are expecting to stay here.
I know plenty of new grads in the South Bay/Peninsula living in apartments or rented houses that would be considered decent or nice in the rest of the country with plenty of money to spare. Mostly at bigger, established companies though. Anecdotal, I know, but it definitely seems like there's a portion of new grads living comfortably in the bay area.
Living somewhere and owning property are very different though.