I think the reason for high programmer salaries in the U.S. is due to:
1. Culture that values engineers
In Silicon Valley and in many tech companies, the culture is that high quality engineers are highly valued and respected, and thus command high salaries. Companies like Google, Facebook, and Microsoft were founded by ex-programmers / ex-CS majors, so they understand the value that high quality engineers bring to the table and are willing to pay for them. Whatsapp was bought for $20b and only had 50 employees, 70% of whom were engineers.
In non-tech companies where tech is seen merely as a cost center, programmers don't make that much (eg. fashion companies). For the record there's nothing wrong a non-tech company not wanting to pay top dollar for engineers, some random ecommerce store probably doesn't need world class engineers, just like a semiconductor manufacturer doesn't need the best graphic designers.
I'm not very familiar with the UK so I don't know firsthand why UK engineer salaries are so much lower than in the U.S., but if I were to guess I'd say it's largely because their culture just doesn't value engineering talent like in SV.
2. Tech companies have a lot of money.
The big tech companies have very high margins. Facebook's market cap is $20m/employee, profit is $684k/employee and has a profit margin over 40%. Apple's market cap is $9m/employee, revenue is $2m/employee, gross profit margin is 38%, and they have $245b in cash. Even unicorns that bleed money (eg. Uber) are flush with cheap capital from VCs, with Uber having raised $20b to date.
Looking at it from this metric, it would seem that engineers are underpaid relative to the value they create. Not only just engineers, but labor as a whole.