It is against this background that the concept of "punishment" appears utterly inconsistent, and the idea of imprisonment for twenty years particularly outdated. If a crime is considered that severe, then surely the criminal is considered deserving of psychiatric treatment, and if that doesn't work, it's not twenty years but life on Elba II.
I agree that it makes absolutely no sense, based on what we've seen and what we'd imagine a futuristic, optimistic penal system would be. The only thing I can gather, is that Spock is joking around or, perhaps more logically, making Cyrano sweat a little with some half-truths. Perhaps the old penalty, yet-to-be officially stricken from the books, for transporting dangerous animals is twenty years imprisonment. But its understood that he'd be charged with a different crime or the judge would give him a lesser, more humane sentence.
Perhaps this would explain the ridiculousness of "sentencing" Jones to cleanup K-7 for 17.9 years. As stated above, there are undoubtedly better ways to clean that place up than one exasperated trader. And I have to believe that DSK-7 would rather have neither Mr. Jones nor the tribbles to contend with on a daily basis. Technically, it might take him exactly 17.9 years to humanely extract and remove all tribbles by himself, with allowance for weekends and break periods and vacations and whatnot, and assuming he doesn't develop some sort of quick system. But that is 99.83% unlikely to occur.
Especially since he just ends up using a Klingon hybrid creature to viciously slaughter and devour all the tribbles.