Cosmic history can explain the properties of Mercury