As I understood it from my very limited studies, there are five reasons for incarcerating somebody: retribution, deterrence, rehabilitation, incapacitation, and restorative justice.
If somebody is judged by their peers to have broken the laws approved by their peers, then they receive the punishment deemed suitable by their peers.
As I say, my knowledge of this comes from a brief college-level history about 20 years ago, so may be outdated, naive or just completely wrong.
But I think in the case of Bernie Madoff, incarcerating him was justified to deter similar financial frauds in the future. I suspect (and judging by some of the comments on this page, it might have worked) locking up Andrus Nomm is an attempt to discourage programmers from working for firms like MegaUpload.