Sometimes these "bad apples" are actually decent or good employees, but the disfunctional dynamics, or even maybe bad managers can turn a potentially good employee into a bad one.
When managers are incompetent technically, some tend to rely on few employees they trust on decission. The problem is that these trusted employees become trusted not necessary of their technical skills, but their affinity, (or ass kissing abilities) to their manager.
A good manager, will be able to take advice from all his employees, and even his most technical ones. A bad manager will rely a lot more on his chronies, which, there is a great chance, they are going to be technicallly incompetent.
So, if you are actually good, but forced to implement things you think are stupid, just because your manager happens to trust other people's opinion's more, then it it is going to be frustrating. Some people suck it up, some leave, some just moan and complain, and of course are labeled bad apples.
And this happens way to often, especially in larger companies. Small companies, will go with the technical competence, otherwise die. Technical incompetence and chronyism thrives is large coorporations, with lots of managerial layers.
Sometimes, there are truly people that are bad apples, and shouldn't be there, but often there are people that are great, but slowly become a bad apple b/c of the above circumstances.