The Sidewinder isn't designed to go off when it actually hits the target; it's designed to go off when it gets very close to the target. The missile control system uses an ingenious optical target detector to figure out when it's within range.
The detector consists of eight laser-emitter diodes and eight light-sensor diodes arranged around the outside of the missile airframe, just behind the flight fins. When the Sidewinder is in flight, the detector is constantly emitting laser beams in a spoke pattern around the missile. If the missile gets close enough to the target, the laser beams will reflect off the aircraft body and bounce back to the sensor diodes. The control system recognizes that the missile is right next to the target and triggers the warhead.