How is a court-appointed defense attorney supposed to do his job if he knows his client is guilty?
The legal system is convoluted enough that it requires a guide and domain-specific expertise. That doesn't mean the public defender's goal is to get them off, simply to serve as that guide and offer them the ability to understand their challenges and options.
Sometimes you're guilty as shit and it's unambiguously on camera, so the defense attorney's job is not to magically get you off -- that ain't gonna happen -- but to ensure you don't get utterly fucked over by a shitty plead deal and/or that mitigating factors are taken into considerations; e.g. "normally offenders with no record who did $crime only got $sentence; why is this twice as high?"