A nail when rest on the ground then it has some potential energy stored in it due to the gravity but when the hammer is strike on the nail the potential energy of the hammer is transferred into the kinetic energy. If the continuous hitting is done the kinetic energy of hammer is transferred to the nail and we know that the heat enclosed into a body is equal to the total energy that the body possesses. Therefore, as much the nail is hammered, the heat content in it will get increases and so the nail will get warm.