I remember reading this as a short story.
Prisoners where entombed in a mountain. Inside the mountain was a huge horizontal wheel, and the prisoners' cells where like teeth or cogs at the edge of the huge wheel. The prisoners were all forced to pull on a huge chain (or turn some kind of crank or something) to slowly move the wheel. A few holes to the outside of the mountain gave the cells access to the outside as the cell moved into position. So the prisoners had to literally work to their freedom. [Food was provided via much smaller holes that guards would put into the cells.]
It was kind of an odd story. I am not sure I have all the details right, but this should be enough for someone familiar with the story.
[story-identification]
tag and the genre tags should be used for questions about the genre only.