Back then it was likely easier to lay the groundwork than in more populated cities. In addition there were great institutes of higher learning focusing on technology.
Note this is just a small theory and in no way has any evidence to back it.
That's a good question and I'd be very interested in reading about why so many popped up out here. I posed a question about this on Quora so hopefully I can report back soon with some good answers.
On the earlier end, Stanford, UCLA, UCSB and Berkeley all trace their roots back to 1860s-1890s.
But you'd probably have to go back to before the gold rush to go to a time when there weren't many people in the bay area: san francisco had about 1,000 people living there in 1848, 25,000 by 1849, and was the 10th most populous city in the US by 1870, and had 300,000 by 1890.
Los Angeles blew up with the discovery of oil and entertainment and broke the top 10 in the 20's and the top 5 in the 30's.
You aren't wrong, the east coast had a lot more people, but they still do today.
Both H (Bill Hewlett) and P (Dave Packard) were at Stanford prior to WW2. And Silicon Valley pre-dates the Internet era. See Fairchild Semiconductor, The Treacherous Eight, etc.
Note this is just a small theory and in no way has any evidence to back it.