Rules in a civil trial and a criminal trial are different. What I say should be only applied to criminal trial.
When someone is accused of a crime, there isn't just "guilty" and "not guilty". Many actions could be different crimes depending on the circumstances - like theft, robbery or armed robbery, like manslaughter, second degree or first degree murder. So a lawyer might be very well aware that the client stole money or killed someone, but the client might be guilty of theft and not armed robbery, or manslaughter and not first degree murder, so even knowing that the client is guilty, the lawyer would still be expected to give his best defence.
Many crimes can have mitigating circumstances. A person killing their spouse after ten years of being abused, and another person killing their spouse who dares defending themselves after ten years of being abused, should be treated differently, and the lawyer should do their best to make all mitigating circumstances for their client count.
And there is the prosecutor. The prosecutor is not there to get a fair judgement, but will try to get the maximum punishment. Likewise, the lawyer is not there to get a fair judgement for their client, but the least possible punishment. The judge being between them is responsible for a fair judgement. The lawyer must do his best to represent the client, or the judgement will not be fair.
Since I was asked: The case of Aaron Swartz and prosecutor Carmen Ortiz looks very much like a case where a prosecutor tried to get a maximum sentence, way beyond what looked to be justified. That is a case of "knowingly" looking for a sentence that exceeds the crime. But on the other hand, I didn't say that prosecutors generally "knowingly" ask for punishment that exceeds the crime, but it is obvious that in any single case where an innocent person appears in court, the prosecutor at least unknowingly asks for punishment that exceeds the non-existing crime.