What do lawyers do when their client is obviously guilty, especially for insane crimes?

So let’s say someone has gone out in broad daylight and killed 100 people, there’s multiple witnesses as well as evidence. Obviously everyone has rights to a lawyer or legal counsel, but are they required to “defend” someone who is clearly guilty?

I understand lawyers are also there to ensure you are treated justly (i.e., given the appropriate amount of time, not being excessively punished, etc) — but what does a lawyer even say in court in instances like these? Other than trying to convince the court he’s mentally ill and should receive a reduced sentence?