Simulation and theoretical analysis of the origin of the temperature of maximum density of water