It is the proximity sensor. When you put your iPhone up to your ear for a call then it automatically puts the screen to sleep and takes it out of sleep mode after you take the iPhone off your ear.
It is the proximity sensor. It turns the screen off when the iPhone is next to your ear so that random contact by your ear won't affect the touchscreen.