Life is a series of lotteries. Where you're born, how wealthy your parents are, what genetic endowment you receive, what environment you grow up in. You have to win enough times and then you get a shot at a happy life.
Is it fair? Not really. Most people lose. I also lost. But, such is the reality we live in.
Realistically, policy is the outcome of the political process. There is no single optimal policy because what's considered 'optimal' depends on what you want to achieve, and these goals will vary across individuals or groups.
Some people don't want anybody to come in, others want just the brain drain but nobody else, others want cheap unskilled workers, others want open borders. And this is just a small sample.
1. We want to do brain drain to remain a leader in science and technology.
2. We don't want immigration and we don't like immigrants.
3. We can't discriminate based on where you come from, that's racist.
So let's have H1B (satisfies 1), but put a cap on it (satisfies 2), and have a lottery if the cap is exceeded (satisfies 3).
There could be a better solution for reaching these goals, you could switch priorities, cancel H1B altogether, or lift the cap, or have stricter requirements, or separate caps per country of origin, or per sector, there are a lot of options.