That's a whole other problem [1]. Most bad managers I've met were actually quite good at the jobs of the people they are managing. Managing requires a whole other set of skills though.
Some of worst managers that I have met sucked at the jobs of the people they were managing. But they were good at pretending in an environment where upper management is also clueless. Or simply they were promoted to take them out of the jobs they sucked at.
Fair enough. It would seem that a feedback loop exists where managers who promote staff to be managers because they are bad at their jobs, would create more managers who are likely to promote staff to be managers because they are bad at their jobs, which would create...
https://en.wikipedia.org/wiki/Dilbert_principle