When a lot of wealth is generated by a city, a lot of people attempt to move there to cash in on it. The number of people who physically can live in a city is limited by the number of housing units available. If they don't build new housing, then for every person who moves in, another person is going to be displaced, whether that be moving elsewhere or ending up on the streets or moving in with other people. Market mechanisms ensure that the housing that is available goes to the people who are willing to pay the most, which is generally the highly-paid tech workers in SF & Seattle and the financial types in NYC.
The solution is pretty obvious: build more housing.
It's also independent of the amount of wealth that's generated, or whether the new housing is high-end gentrified condos or low-end affordable housing. If the new housing is high-end condos, then all the tech workers move into new construction and people who otherwise would've ended up homeless stay in their existing apartments, or move into the run-down apartments vacated by the tech workers. If the new housing is small affordable units, the high-end tech workers stay put and the homeless move into the new construction.