>>55244299I'm not sure exactly how the spaghetti code works, but my assumption is it has something to do with how pokemon can be found sleeping directly under trees: when you do the glitch correctly, the pokemon that spawns is sometimes getting up from its sleeping pose (Picrel), so my best guess is that trees have some sort of special spawn area so wild pokemon will generate there in the sleeping position and look like they're napping in the shade.
And while a transformed ditto normally deletes itself when you run away (presumably to prevent shit like this from happening), something about this special spawn radius must take priority when the mon is close to/clipping into the tree, and it instead gets treated as a new wild mon being spawned in, instead of a disguise mon that needs to be despawned.
This is all just guesswork though, I can't say why some pokemon are way harder to dupe than others, or why some small mons barely need to be touching the tree to be cloned.