Thermodynamic stability and phase transitions in systems with a chemical reaction