Accurate description of phase transitions in flexible materials using transferable machine learning potentials