Here's what happened:
* The original sword was destroyed. The Death Eaters stole the sword from the Chamber of Secrets in *Harry Potter and the Chamber of Secrets*. Voldemort used it to create his Horcruxes, and it was later destroyed when Harry destroyed the locket Horcrux with a basilisk fang.
* A new sword was created. The sword that Harry used in the final battle was a replica made by Godric Gryffindor's ghost. He created it specifically for Harry in order to defeat Voldemort.
So, there wasn't a switch, just a replacement. The sword that Harry wielded was a new one created by Gryffindor's ghost, not the original sword that was destroyed.