The teachers I've met at my nieces primary school have been uniformly great at teaching the grades they're responsible for, though none of them are software developers. Our society doesn't value teachers as highly as it should, given their role in shaping the future of our society - for one, they ought to be paid considerably more than they are (that would attract the higher caliber candidates you want), but we also need to fund schools better than we're doing now - there are thousands of stories out there about teachers having to buy supplies for their classrooms out of their own pocket, because the school can't supply basic needs.
Teaching is a skill for which one can have (or not have) an aptitude, just as software development is - I think I'd rather have us teach good teachers how to program (knowing that not all will get it), than teach software developers how to teach (I imagine there might be a higher failure rate there).
I took us off topic and now I'm taking us further afield (sorry mods) but I've thought for some time the pay scale for teachers should allow for differentiation by subject matter. Mainly allow the STEM fields to get closer to market rates teachers could command if they went into private enterprise. I don't mean this as a slight against those teaching in the arts and humanities (personally I work with a lot of creatives who are very skilled in what they do and well paid for it) but typical salaries for an artist who may work in something like graphic design in the private sector would be significantly less than a programming instructor who would otherwise be a developer. The current policies of tying all the salaries to the same scale of tenure and level of education (bachelors/masters/etc...) limit the ability to attract and retain the best resources in areas more in demand in the private sector. This change would likely increase the overall costs for teacher compensation but some of the increase for tech fields would be offset by reductions in other disciplines.
I agree with you that being proficient in an area and being a good instructor are separate qualities. Not every great programmer would be a good addition to a classroom (again, working with many I'd say the majority wouldn't in my personal experience). I would like the inverse to be true though and today I don't think it is. There's some truth to the old adage "those who can't do, teach." Obviously not universal as people pick a profession for many reasons, compensation being just one, but I do believe what I've laid out above contributes to that. If you have an individual who is adept at teaching and (as you would hope) is very good at the topic they teach, they may often elect to join private industry instead of going into teaching. i.e. if I'm a talented programmer who can also teach and I have the option of taking a teaching position for $40k/year eventually working my way up to $75k after getting an advanced degree and spending many years on the job or I can become a developer starting at $75-80k and working up to an architect at well into six figures, I think many follow the paycheck. Some will be altruistic, some have a passion to inspire young minds, some like having summers off and other schedule perks, but I think pragmatically most with the highest level of ability are going to chase the payday.
One could make the argument to increase all teacher compensation across the board to address this but I think it's unrealistic to say our programmers/chemists/physicists/etc... can make $150k so we're going to pay our literature and art history teachers that as well. Splitting by discipline makes sense to me.