Even among countries that are often assumed to have broadly similar standards of living by most people (UK is example I am most familiar with), those countries often pay their engineers substantially less. Many of my British colleagues earn very _substantially_ less doing the same job for the same company in the UK as an equivalent US worker.
Of course money isn’t everything, but it’s not like quality of life in California is completely terrible either for a lot of people...
Also when we talk about long waits for Green Cards, we really mean for the large body of Indian technology workers, broadly speaking. For other nationalities the wait is typically a year or less (for those unaware there are effectively country based quotas for green cards). The gap in earning potential is even larger still in the Indian example vs my earlier UK one, so again I’m not surprised few actually move back.
Finally many of these visa workers have had to battle their way to a job. Unlike a US citizen, they’ve had to brave a complex, often uncertain immigration process, finding a job in a foreign country in which they may have no experience, no network etc. If you put in all that effort, it’s maybe not surprising you want to hang around to get the eventual prize.