At around 2000 - 2010 San Francisco had the reputation of being an amazing city. It wasn't a tech hub back then but it was a very cultural city with a lot of diversity, art and amazing views. A lot of people just wanted to live there, including tech workers. One my friends worked at google and lived in SF because she told me she was so "enamored" by the city.
In fact that's why those google shuttles exist. Because back then tons and tons of people loved the city so much that they wanted to live in SF while working in Mountain View.
When tech started rising more and more, tech workers started moving into SF turning it into the tech hub that it is today. This upped property values which in turn drove a lot of junkies and homeless people out of the condemned properties as those properties were getting repurposed to take advantage of the growing market.
That's why you see shit on the streets and needles everywhere. Rising property values essentially took what was happening behind closed doors and put it in the middle of the street. Everybody applauds all the social programs offered to the needy by SF until it they see it up close and personal.
So really there's two main root causes for why SF is the shit hole it is today:
1. Excessive amount of tech workers.
2. Drug availability.
The Tech worker thing is new. The Drug problem is old, although I'm not sure how much the recent opioid epidemic contributes to that.
Anyway this seemed like a tangent but to address your point: Companies wanted to move to SF because the tech workers WANTED to live there. The companies relocated based off the location of talent.
The situation today is the end result of a feedback loop produced by Tech companies and Tech workers from 2010 to now. Tech workers move to SF, so companies follow. This causes more workers to follow the companies.
You'll see this correlation everywhere. If companies don't want to be in a certain city, for sure there's an amount of skilled workers who don't want to be there either.