It doesn't help that teaching is presented as a "caring" profession, that you do for the love of your charges. Teachers don't threaten to jump to a different school district for more money, and when they campaign for more money, they're presented as not caring about the students. Nobody expects programmers to have any loyalty, so they get to demand money.
I would love to have schools fight to get the most talented teachers, instead of settling for "any woman who likes kids". (Those "caring" professions are usually ones associated with women.) I'd love to see school systems compete with software companies and research institutions, and to have school districts run by the people who might otherwise run Fortune 500 companies. But that won't happen without money, and until we start deciding to pay for it, we're going to get a lot of mediocre teaching.