It doesn't really matter whether the defendant is guilty. Even someone who 100% admits their own guilt and has been found guilty beyond a doubt still has rights and considerations of due process -- this is what we've all agreed to as a civilized society -- and the public defender exists to ensure that even if a defendant has no financial means or connections, SOMEBODY knowledgeable is working to ensure that those rights and considerations are respected.
It's a critically vital function in preserving the rule of law.