Why is banging a temporary magnet on a hard surface demagnetize it?

The magnetic properties of a temporary magnet are derived from the fact that its molecules are aligned along the magnetic polarity: they mostly point in the same direction and so one end of the temporary magnet is North and the other is South. Banging the magnet can knock some of these molecules out of alignment so that they face random directions. As a result, there is no particular direction in which is then North and South and so magnetism is reduced. When enough molecules have been knocked out of alignment you are left with a demagnetised piece of metal.