Several reasons come to mind including better laborers. But also politics, culturalism, tax incentives, racism, bribery. Employment law has a large share of the legal market, keeping with litigation. We should have no expectation that companies are only hiring for company profit. Employees and managers appear to be, often times, doing what's best for themselves.
Some healthy subset of companies just want to hire the best people they can get that will accept their offer, and sponsoring an h1b is a small part of the overall costs.