How did I lose my Blastoise?

I just started up a save file where I was outside the cave in Lavender Town and my Blastoise turned into a Gengar. I had a Gengar right next to my Blastoise, and the Gengar that replaced my Blastoise had the exact same stats as the first Gengar. Can anyone tell me how this happened?