I believe that the punishment may have euphemistically been referred to as some kind of exile (maybe in order to get around capital punishment not being legal?), but it was actually a death sentence because the prisoner was 'exiled' into such a small space that they couldn't possibly survive, like an inch wide or something. It may not have been a way of getting around legalities though, it could just have been a really weird method of execution.
In the scene I remember, the character finds themselves in one of these chambers - and the wall is advancing towards him slowly as if driven by a piston. But he scrabbles at the wall at the back and finds some loose stones or bricks that he's able to pull out and I think he climbs up the wall somehow before the piston crushes him - suggesting that this was some kind of apparatus located outside, I don't think it was indoors. I really thought that it was supposed to be at the very edge of the city (?), hence the 'exiling' to just outside its limit against a wall, but I could be misremembering that part.
I think it stuck with me because I found it disturbing, but now I can't remember anything else about the context at all, at first I thought it was from Emphyrio by Jack Vance but it seems not.
I believe the general setting was kind of an anachronistic SF, like not hard or high-tech SF but some kind of really odd society with fantasy elements, which is perhaps why I remembered it being from Emphyrio which has that kind of vibe.