Apostrophes are used for two purposes: to show possession and in contractions.
POSESSION
In the case of the expression "a winter's day" the day belongs to winter. However, in this case, the years don't belong to the jail. Do you understand?
CONTRACTIONS
I cannot swim. OR I can't swim.
They both mean the exact same thing, it's just an abbreviation.
But this case doesn't use contractions.
A simple way of explaining this is to talk about "one year's jail". If it's one year in jail, why is there an "s" on the end of year? It's not there to signify that it's plural, so it must be there to signify possession. In which case it does have an apostrophe. So, "five years' jail" is correct.
I think the expression "... ten years' time" suggests a more correct meaning. It's the time that punishes, not the ten years. The ten years are simply a qualifying length of that time.
Proof? Try changing it from 10 years to 1 year.
Aha! Can't do it without an apostrophe, can you!
(and that would be ... a year's time, not a years' time, eh!)