Cycles of destabilization and repair underlie evolutionary transitions in enzymes