The intense pain associated with touching, or being touched by, an object that is damagingly hot is initiated via specialist cells in the skin called TRPV1 cells (Transient Receptor Potential cation channel subfamily V member 1). They are a sub-category of 'nociceptor' (a sensory neuron that responds to damaging or potentially damaging stimuli by sending possible threat signals), and can quickly and accurately detect temperatures above 42 °C - by an as yet unknown mechanism.
“Thermal nociceptors are activated by noxious heat or cold at various temperatures. There are specific nociceptor transducers that are responsible for how and if the specific nerve ending responds to the thermal stimulus. The first to be discovered was TRPV1, and it has a threshold that coincides with the heat pain temperature of 42 °C. Other temperature in the warm–hot range is mediated by more than one TRP channel. Each of these channels express a particular C-terminal domain that corresponds to the warm–hot sensitivity. The interactions between all these channels and how the temperature level is determined to be above the pain threshold are unknown at this time.” [ source : Wikipedia ]
Although the workings of the TRPV1 cells have been extensive investigated (see Wikipedia ) the crucial part of their operation - how they accurately detect the harmful temperatures - is unknown.
Note: The cells' trigger-response can also be initiated by various chemicals - notably Capsaicin as found in chilli peppers.