One, lots of people want to work in physical proximity to their coworkers. I know I am one of those people; I could work remote, but I enjoy the social aspect of working in an office.
Second, part of the appeal of living in one of these expensive cities is that the amenities are also nice. When you cluster a lot of wealthy people together, the public services get better, there are more entertainment options, etc. Being a wealthy person in a cheaper part of the country might sound nice and have its perks, but you are going to find fewer places to spend the money you have.
Third, people like to live with people in their same class. We really hate talking about class in the US, but it is there nonetheless. It is not easy to be a well off tech worker when the people in your social circle are blue collar workers struggling to make ends meet.