I'm not sure what things you think they are doing that are illegal.
The help that is available, such as shelters, have strict rules and limited space available. What that means is if a person can get a bed for the night, it's for that night only. The person has to hang around the shelter all day long, waiting for the shelter to open for the evening, because the people who stay there are kicked out early in the morning. Also, if they do get a bed for the night, they are not allowed to bring any of their personal belongings with them, and certainly aren't allowed to bring their pets. That means anything left outside the shelter is pretty much guaranteed to be gone the next morning. So, if they don't score a bed for the next night, they're left with absolutely nothing and are worse off than before.
Many of the people who are homeless do have substance abuse problems. There are very few clinics that will offer help to people with substance abuse problems who are homeless. It's a vicious circle for these people.
Finding and keeping a job is almost impossible for a homeless person. But they need employment and an address to get help. But they can't get help unless they have an address. But of course, no one wants a shelter in their neighborhood -- that would lower property values. But of course, no one wants these people on the streets, because they're annoying and scary.
Our country, back in the bad old days, shut down almost all of our state hospitals because they were expensive to taxpayers, and because many of them were poorly run. So, instead of doing the hard work to fix the problems, congress decided to try to make the problems disappear. Unfortunately, the people who needed those services didn't just go away -- they're on the streets.
Most of these people aren't violent. Avoid them if you want to, of course, but having someone ask you for pocket change isn't assault.