The stereotype of the undocumented worker (you know, the "illegal immigrant" Trump's wall is supposed to stop) is of someone who crossed the Mexican border in the middle of the night. Those people exist. A lot of other undocumented workers are people who overstayed their visas. That is, they entered completely legally and then didn't leave. Maybe they found a nice job that they wanted to keep past the expiration date. Maybe they had a kid. Maybe they had nothing to go back to except poverty and homelessness.
Anyone who has ever tried to live/work in another country with proper paperwork - basically any country - knows what a nightmare the bureaucracy is. Until/unless you manage to get a green card/green card equivalent it's difficult say that you're ever really quite legally allowed to be there. And even then there are still gray areas to navigate. It's more of a constant process of overlapping stages, continually hoping the right papers come through at the right time, until the next time, than what I think people imagine is some nice process in which you apply and then the papers show up. You're pretty much always at the mercy of the system, hoping the immigration official gives you a pass because the truth is you're never quite 100% assured of being allowed to stay. Absent paying immense amount of money to a lawyer/broker (or finding some pro bono help), these aren't processes that mere mortals can be expected to figure out successfully, especially in another language. They're opaque in part by design.
I'm pretty sure I was working illegally in another country once. I say "pretty sure" because I honestly never figured it out. You have a hiring date, you think you've done everything you're supposed to do, you discover you haven't, and then suddenly you have no job and no place to go because some form isn't filled out correctly. Or you just stick with the plan and hope for the best, and hope your intended employer either ignores or smooths over the problems. I'm sure I wouldn't have been homeless - I imagine mom and dad would have taken me in - but I would have been jobless and cashless for awhile. Not that I think we should see things this way, but I was a "high level" immigrant going for a white collar job and I didn't have a backup plan. If there's one area US bureaucracy rivals and exceeds the caricatures of horrible bureaucracies elsewhere, it's our immigration system. Being "legal" is a complicated concept.