I would argue it also belongs in decisions of whether to convict and what to convict someone of.
The law cannot encode the entirety of human experience, and can’t foresee every possible mitigating circumstance. Given the fact of a conviction regardless of sentence can have such a huge impact on someone’s life, I think there is room for compassion and good judgement in multiple places.
You're describing sentencing. Conviction decisions are mostly made by juries.