Pretty much all criminal laws are like that since only a fraction of crimes will ever lead to an arrest we make examples out of those are caught to make others less likely to commit crimes in the future when they see the punishment. The deterrence effect is basically "risk of getting caught" * "punishment if you get caught".
It's not just the deterrence but to publicly condemn the act. Condemnation needs to have teeth and the perpetrator needs to feel the burden, otherwise it's just empty words on paper. The burden is necessary to establish social balance. The punishment can't be enjoyable, it needs to take away the unfair advantage gained by the criminal act, it provides a way to repay moral debt back to society.
> A fourth feature of punishment, widely acknowledged at least since the publication of Joel Feinberg’s seminal 1965 article “The Expressive Function of Punishment” is that it serves to express condemnation, or censure, of the offender for her offense. As Feinberg discusses, it is this condemning element that distinguishes punishment from what he calls “nonpunitive penalties” such as parking tickets, demotions, flunkings, and so forth. (Feinberg, 1965: 398-401).
https://iep.utm.edu/m-p-puni/