I think this is the core of the problem. If H-1B were actually being applied as the law is written, I don't think anyone would have a problem with it, at all. Unfortunately, it appears that the government is doing almost nothing to prevent abuse, probably because of lobbying from tech firms.
You are right, though, the practice of using the visa program to replace existing workers with lower cost alternatives which they must train is clearly not allowed.