As much as I kind of hate to say it, Mister's explanation is a bit wrong. ^^;
Also, I did a little bit more research on the glitch.
While he has most of it right, he's wrong about the error in the stack. The game doesn't crash because of "an unexpected program", but because the stack overflows. Since sprite IDs as high as #255 were not made to exist, the stack fills up with all those empty values (which there are only 245 of). To quote the SMWC:
BIG FAT NOTE: Keep the push/pull in balance. Otherwise the stack will overflow, causing the game to crash eventually.
Since the stack is never meant to overflow, and has no codes related directly to the stack, the game crash does in fact end up randomized, based on how many values are in the stack and what they are set to. When the stack contains certain values, however, results such as the powerup incrumentation glitch will occur.
In short summary, the reason the PI glitch happens is because the stack overloads, and while the crashes the stack causes are randomized, certain values will always produce similar results.
Now to figure out what values do what and how to control the results of collecting powerups afterwards.