As a former teacher who is currently by all accounts a fairly capable software developer, this saying drives me up a wall.
I took 2 years out of my life to work for almost nothing so I could share my love of math and programming with the next generation. That I eventually gave in and moved into software engineering to make money says far more about my lack of altruism than my competence then or now.
But forget me, I taught in a cushy city post, I know some people in the peace corps (I taught abroad) who are still in the game, teaching math and English out in the sticks, sometimes having to build or maintain their own school buildings and learning the local language with no assistance. The idea that the defining trait of teachers is a lack of competence is laughable.
Please don't perpetuate the misuse of this phrase, which is so often used to denigrate those with expertise and desire trying so hard to pass them on.
Consider the possibility, say, in a guild context: those who can, do. They work for the guild, and do whatever the guild does. Those who can't, from age, infirmity, injury: they teach, passing on knowledge and wisdom.
In my experience this is likely one half of a principle in which there are at least as many examples of people who can do things really well, but have no idea how to pedagogically transmit the building blocks of their domain understanding to others in a tractionable way.
Maybe a more wholistic take on this is something like:
'Those that can't do, teach, and those that can't teach would really be doing everyone a huge favor if they would just go do somewhere.'
If this is a more complete take, it suggests to me that the master/apprentice paradigm existed for so long for a reason; masters have spent their lives specializing narrowly, not necessarily transmitting their understanding, thus the deconstruction of their expertise is only accessible via osmosis over time, because essentially they can't teach.