I have looked at the routine once so I can tell you what it does and what shenanigans can appear (though the explaination is a bit difficult for me to describe without a flowchart): The routine at $00F1F9 handes the ?-coin blocks for the switch palace tileset. The first thing it does is to get the group i.e. the level is split vertically into groups with a height of four blocks where the first four blocks make up group 0, the next four group 1, etc. It spans over two subscreens so group 8 is identical to group 0 and so on. It then takes the horizontal position within subscreen and use that as an index to $00F0EC which is a list which blocks will change in case you are unlucky. That value is always kept track in $13F3,x (where X is the group ID).
Now we get to the part where jank appears: Only blocks at a certain column are effected as seen by the table $00F0F8:
Code$40,$50,$00,$70,$80,$00,$A0,$B0
Basically, only the columns where the ?-coin blocks are normally located but also the leftmost block of the screen are effected while no other block can be affected.
How does the game know which blocks to affect and why it never happens when the blocks are placed as intended? With the table of $00F0EC, of course. $00F0EC contains a list of values which tells you which blocks still can be activated on that current group and which one can't. That works bitwise where bit set means no block can be activated in that group while bit clear means there still are blocks which can be hit. This is dependent on the block's X position but it does result in jank if the posions aren't as expected:
Code$08,$01,$02,$04,$ED,$F6,$00,$7D,$BE,$00,$6F,$B7,$40,$50,$00,$70
Usually, only two bits are clear (so only two blocks get affected at most). However, only positions 4, 5, 7, 8, 10 and 11 are valid (the bold values), while 0 - 3 and 12 - 15 will load garbage values and 6 and 9 are set to $00 which may result in more blocks getting activated than expected.
To see the maths in action:
Code$ED = %11101101
$01,$01,$01,$00,$01,$01,$00,$01 ; Bitmask
$40,$50,$00,$70,$80,$00,$A0,$B0 ; Positions
$00,$00,$00,$70,$00,$00,$A0,$00 ; Affected positions
But what if the position is invalid? Then this happens:
Code$50 = %01010000
$00,$01,$00,$01,$00,$00,$00,$00 ; Bitmask
$40,$50,$00,$70,$80,$00,$A0,$B0 ; Positions
$40,$50,$00,$70,$00,$00,$A0,$B0 ; Affected positions
As you can see, now five blocks are changed instead of the intended two (plus the block at that position)!
There is some further jank: When you activate the block, the X position's value is OR'd together with $13F3,x (after all, the game will need to always give you a 1-up if you timed the ?-blocks correctly twice which happens when no block is set to be unactivated). This allows you to create further jank where only selected positions will cause a used block (though as a side effect, this will stop most glitches as well).
Interestingly, if you look up what
$13F3, you'll notice why Mario may get suddenly inflated if he hits a ?-coin block at the Switch Palace tileset: The coin block table is actually kept track at
$13F4 meaning only groups 1 - 5 are valid while group 0 (aka the topmost four blocks) points to $13F3 which is the inflated Mario state (this causing the infinite P-Balloon glitch if you enable a coin block at the first four blocks of a level save for two positions), group 6 points to $13F9 which puts Mario behind the foreground (but only temporarily) while group 7 points to $13FA which allows Mario to jump out of water (no effect practical effect).