The teacher union means no teacher gets fired for performance. My wife worked in public education as a teacher for 20 years.
They aren't programming robots. A lot of students, especially the ones who have not been taught from an early age the importance and rewards of knowledge, simply aren't interested in learning.
Anecdotally, I had an adjunct teaching gig at a state university many years ago while I was in between jobs. My mom is a retired public school math and science teacher, and was on her district's union negotiating team. I described my gig to her, and her response was: "Now you know why teachers have a union."