I guess I can try listing the possibilities.
1. Accidental push to the B button (unlikely)
2. Here's something similar that happened to me (very unlikely, but I'll give it a shot). Since I was battling a wild pokemon, I was not confident that it will level up. I wanted it to hold a Lucky Egg just in case, but I gave it an Everstone instead (yes I actually did that xD) and it didn't evolve. Doubt anyone else makes that error though...
3. A glitch