Unveiling quantum phase transitions from traps in variational quantum algorithms