The thing to remember is that salaries are set by market forces. Specifically the competition between buyers (employers) and sellers (employees).
Compensation for a position ends up as a range between 2 numbers:
A floor, below which nobody would agree to take the job
And a ceiling, above which leaving the position empty costs the company less than the salary would.
For a Junior Developer in the Bay Area, those numbers are probably something like a floor of $80k (because the cost of living is so high), and a ceiling of $300k (Facebook makes $2.4 Million of revenue per employee. Even for junior developers, the cost of not having an employee to fill a position that needs filling is probably hundreds of thousands of lost revenue).
Imagine a theoretical auction. Usually, there is just one thing being sold and multiple people trying to buy it, so they end up bidding each other up to the highest price any of them is willing to pay (the Ceiling).
Now imagine a different auction where there is just one buyer and multiple people trying to sell them the same thing. The dynamic is reversed and now the buyers are going to keep offering lower and lower prices until they get to the lowest any of them is willing to sell it for (the Floor).
The same dynamics happen in the jobs market.
When there are more jobs than people who can fill them, you get intense competition among companies and they end up paying salaries near their Ceiling.
When there are more people than jobs, you get intense competition among employees and they end up settling for numbers near their Floor.
Taking Facebook again, the current salary for a junior developer in California is $110k which means salaries are only slightly higher than the cost of living.
Ergo, if an employee moves somewhere where the cost of living is cheaper, their Floor is going be lower (because cost of Living is lower) and Facebook can negotiate them down to their new Floor, knowing that the employee will accept it.
If you were earning Cost of Living + $20k in California, then you'll probably accept earning Cost of Living + $20k somewhere else as well.
Facebook knows this, and negotiates accordingly.
If it were the other way around, and companies were desperate for workers, then there would be no reduction because salaries would be being driven by companies' ceilings which have nothing to do with the Cost of Living.