Generally, states have to balance a number of things in enacting their criminal laws.
For example, states may need to balance the rights of their citizens to be secure against the need for the state not to spend too much money. If the state were only interested in the first of these things, it could impose extremely harsh punishments on those who break the law. Because the state has to think about money, though, it has an interest in imposing shorter terms.
Similarly, the state has to find balance between the security of the public at large and the interests of those who might commit crimes. A state that cared only about the first might again impose very harsh sentences. But the state has to guard against imposing sentences that are too lengthy because those would be unjustly harmful to the interests of people who commit crimes.
At all times, states have to balance between security and freedom as well. They have to avoid criminalizing behaviors that are merely offensive while still making sure that they do not allow behaviors that are truly dangerous or which create actual problems for society.