It was a plot device, plain and simple. It doesn't matter how the cells shift around, it's the DNA that's important, and that doesn't change through metamorphosis. Someone correct me if I'm wrong, but I'm pretty sure that after a caterpillar becomes a butterfly, certain genetic traits are deactivated and others are expressed for the first time, while the physical chromosomes remain constant.