The sensory nerve that detects the heat is connected to the nerves that move the muscles of the hand. Such a connection of detecting the signal from the nerve and responding to it quickly is known as a reflex arc.
Reflex arcs are formed in the spinal cord and the information reaches the brain and brain responses to it.