Very rarely, in my experience. The only dev I've worked directly with that was fired over job performance was first fired when he deleted the entire contents of the corporate IMAP server for a dozen or so people without having verified the most recent backups were up to date and working. We didn't lose enough for it to cause a lasting problem, but it was what finally demonstrated to the CEO that he was careless enough for us to fire.
His code was atrocious, but we'd put up with that until the IMAP incident because getting the CEO to understand that his code was bad enough for him to actually be a net loss in performance for the team didn't work until we had to scramble to recover what we could of the corporate e-mail.
Last I saw he was a senior developer somewhere more prestigious than the position he was fired from. Maybe he's improved. Or maybe he's just managing to stay above the threshold they'd fire him for.
A lot of bad developers just learn to fly sufficiently under the radar and hunker down and accept that they probably won't get many raises until they move jobs and can point to X years of service in company Y, aided by lack of willingness at many companies to stick their neck out when it comes to giving bad references (a lot of places I've worked, HR policy has been clear that we were only allowed to confirm dates of employment).
depends. often the meritocracy of performance reviews is skewed by extroversion and pleasantness of a person toward management, which doesn't have much of a way to judge real skill unless form a technical background and actively working on the codebase.
The key difference between good and bad engineers is that good ones deliver the product/finishes the projects (add bonus points if on time) and bad ones don't. Quality makes much less business sense and is usually only important to the engineer himself and his peers than managers that pay his wage. That's especially true in current "move fast and break things" environment. I have seen a fair share of bad engineers (by this definition) fired, even though they had decent technical skills.