This is part of Brian W. Aldiss's Helliconia Winter, part of his Helliconia trilogy.
Set during late autumn in the northern continent, Sibornal. The book's protagonist, Luterin Shokerandit, is the son of the Keeper of the Wheel of Kharnabar, located above the far north of Helliconia. The Wheel is an extraordinary revolving monastery/prison built into a ring-shaped tunnel with a single entrance and exit, powered entirely by the efforts of the prisoners pulling it along by means of chains set into the outer wall. Once a prisoner enters a cell of the Wheel, it is impossible for him to leave until its full ten-year rotation has passed.
The same prison was also addressed in Aldiss's "Manuscript Found in a Police StateManuscript Found in a Police State".