How it looks in software and softpoly now:

how it looks in hardware (and used to look in software some versions ago, I think I had something like 4.1.x before this):

The extra strips on top seem to perfectly correlate to how far it's offset downwards. It's like it takes the height of the texture and actually tiles it so that the above-ground part of it reaches that height.
I have attached a wad where I cut out a room from my level that demonstrates this (the screenshots are taken from it too). There might be more cases where something like this happens, like if it's sunk into the ceiling, and I'm not sure if every aspect of this particular case is required, but I've tried a normal fence midtex and it didn't have this weird wraparound, so it being scaled might be necessary.