You can learn it in a few months in your spare time if you're cut out for it, which the vast majority are not. CS education for programming jobs is mostly a very expensive formality to convince hiring managers you know what you already knew before enrolling, or at least it was in my case.
"You can learn how to be a lawyer in a few months in your spare time if you're cut out for it" would be considered a ridiculous statement. Perhaps you could learn enough to be an assistant to a legal secretary.
They're not the same thing at all. Being a lawyer involves cramming in an enormous volume of rote information over many years and passing an exhaustive exam; programming is just a combination of problem solving, being able to deal with abstract concepts and how computers work, and learning a relatively small amount of syntax and general concepts. You can easily get a grip on all that in a few months if it's your thing.
I'd say there are tons of hidden dependencies you have to learn in writing programs. Stuff that the tutorials and books often leave out. And that most developers take a few years to learn these dependencies, because there currently is no widely-known easy way to learn all this "tribal knowledge".
And when universities try to systematize ways to learn this tribal knowledge, they come up with a curriculum that takes most people 4 years to get through. (Yes there are many smart developers who could learn the curriculum faster.)
> learning a relatively small amount of syntax and general concepts
In what programming job?! Junior frontend dev churning out React components? Even there you're dealing with a dizzying array of HTML, CSS, and ever-changing JavaScript/Babel/Webpack/etc. insanity. In a few months you can barely produce some simple, low-quality code. It takes a lot longer for the concepts of good quality code to sink in.
Law is similar to programming in that you can learn a lot of the principles in a few months, and you can also learn how to do a lot of the day-to-day work in a specialty area.
Learning large volumes of case law is analogous to learning the details of low level programming; both fields require years to master. But those details are not required for a lot of work in either field.
There was a time when it was possible to sit for the bar exam without having to pay rent to a law school, but naturally the law schools lobbied to change this.