It is hard to believe that a planet that is so close to the sun can be cold at times. However, it really has nothing to do with the temperatures necessarily. The temperatures do change and can get extremely hot but they can get cold too. There are other reasons which include that this planet only faces the sun on one part of the planet.
The part that is not facing the sun would be cooler. Also, this planet does not have much of an atmosphere. The atmosphere can hold in the heat like a blanket. Yet, gasses escape this atmosphere and therefore the heat does not stay close to the surface. At night Mercury could get really cold as a result of those reasons.