Revealing the thermodynamic background of the memory effect in phase separating cathode materials