The game just checks whether the player and Spiny face different directions. By pressing the opposite direction just before touching them, one can kill them.
The opposite also holds: you can die while killing'em the right way if you press backward just before.
Edit entry: Glitch: killing Spiny from behind