Molecular dynamics simulations reveal the mechanism of the structural memory effect in alpha-berlinite (AlPO4), where a single crystal transforms to an amorphous solid by compression and then reverts to the original crystalline structure upon release of pressure. The enhanced oxygen coordination around the aluminum atoms in AlPO4 at high pressure leads to a mechanical instability that causes the phase transformation. The difference in the structural memory behavior between AlPO4 and isostructural alpha-quartz, for which the pressure-induced amorphized phase is recoverable, can be attributed to the presence of the PO4 units, which remain essentially four-coordinated even when severely distorted.