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.
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.