Hmm.... maybe each of those blocks can really be two blocks (like, two blocks in the same position, but one is shrunken to 0.01 scale or something so you can only see one at a time) And the block on top will have ground collisions on top and bottom and walls on the side, like usual. But the bottom one will have ground on the sides and walls on top and bottom, and these collisions will be attached to the models and everything.
So once the blocks make a ~90 degree or whatever turn, shrink the orignal block and make the shrunken one replace the big one, so now that it's been rotated 90 degrees, the top is ground and the sides are walls.
Uh... I'm not sure if I communicated that idea effectively, but I think it can work...?