One of the many aspects of the role of criminal lawyers is to consider what submissions and mitigations they are going to make to the court, in relation to sentencing should a client be convicted of a crime.
This requires a thorough knowledge of sentencing rules as they apply in that jurisdiction, what the maximum and minimum sentences might be for any particular crime, and the circumstances that exist with regards to it.
To some extent, punishments for committing a crime are set in order to act as a deterrent, but obviously, if someone has already committed and been convicted of that crime, that deterrent has failed in their instance. However, that does not mean that the knowledge of punishments such as prison sentences, do not act as a deterrent to others.
When it comes to sentencing and the punishments for crimes, there are basically three distinct entities that have a bearing on them. The first is the parliaments that determine what constitutes a crime, pass laws to enact them, and within those laws, there will be sentencing criteria also.
The next entity is the courts, and that will obviously include judges who hand down the punishments. They have leeway with regards to what the punishment may be, although these will always have to be within the boundaries of the law as it applies to any particular crime.