I have an Indian dev friend who's here on an H1B in exactly the situation that KorematsuFred describes. H1B is just a more sophisticated "Gentlemen's Agreement" (a racist way of using Asian peoples' labor while denying them the benefits of citizenship).
Different reasons for different people. Some combination of:
* It's better than the alternative, and it can be made to work, since once I140 is approved you can renew H1 indefinitely (unless sth goes wrong, like right now, but that's a risk that doesn't look so big initially when all is still well).
* The wait only became this bad around 2008 or so. At the time, nobody knew there wouldn't be a realistic chance to get to gc. A lot of people have been in the system since that time.
* It doesn't always start with wanting to move to the US permanently. You go to a US college, or move for a job in the US (maybe the company you've already been part of offered it, maybe not), thinking it'd temporary. Then you build a life, make friendships, and realize you want to stay.
* Or maybe your parents moved when you are a kid and the US is all you know. But when you turn 18, it's F1/OPT/H1 or go to a foreign country (that you happen to be a citizen of, but have no real relationship with).
Above are all real examples I personally know.
Also, while for non-Indian immigrants it is at least possible to get a gc eventually, this is also by no means certain. Very stressful as well.