Because enforcement wasn't done correctly, because it wasn't taken seriously.
The debate on the enforcement of immigration laws has a lot of parallels to drug prohibition. We could, if we really wanted to, stop both illegal immigration and the illegal drug trade. But the question is, do we really want it bad enough to do what it takes?
If we really wanted to put a stop to illegal drug use, we could do it. We could institute mandatory random drug testing of all citizens. We could apply the death penalty to minor drug offenses, etc, etc, ... But most of us don't think it's worth turning our nation into a full-blown police state to curb drug abuse.
Likewise, we could virtually eliminate illegal immigration if we wanted it bad enough. If we erected enough walls and fences, stationed enough armed guards and drones, and punished violators ruthlessly enough, we could put a stop to almost all illegal immigrants. But would it be worth the cost?
Most people aren't willing to answer 'yes' to either one of those questions, which is why we don't see such draconian efforts implemented. Yet that leaves us in a really bad place. Laws that can't be enforced consistently, or that we don't have the will to enforce consistently, make for bad government. They erode respect for the law in general and demoralize those tasked with enforcing laws without solid support to do so.
We need to shit or get off the pot. If we're not willing to 'kick ass and take names' over drug abuse or immigration (I'm not) then we need to replace the existing laws with policy that we
are willing to enforce like we really mean it.