Good CEOs in good companies makes much more than the average CEOs in average companies.
Every company in the USA wants a good CEO. But there are only very limited number of CEOs in the USA that has a good track record of running a successful company. So companies are willing to pay more and more for the top CEOs.
It's the same reason why drivers are paid very low. If there were only 100 drivers in SF who were capable of taking you from point A to point B with a reasonable amount of certainty they would be also be paid in millions.
Everything is supply and demand.
In case of SanFrancisco, the supply of good engineers that are available to be hired used to be limited compared to the demand.
Once you remove the restriction of being able to be physically present in SF, the supply increases much more than the demand. Which results in the reduction of salaries.