Your proximity sensor is not working correctly. Do you have a case around your phone? If yes, remove it and try again. Same if you have a protective film over your display. The sensor should not be covered by anything in order to work as expected.
If nothing is covering the sensor, try to reset the phone by holding the sleep and home button for about 10sec, until the Apple logo come back again.
The proximity sensor is located next to the receiver of the iPhone.
- Verify mute or speaker have not been activated, just prior to placing your ear over the receiver.
- While on a call hold your hand over the top third of the display, and verify that the screen is locked or goes to sleep.
- Try turning iPhone off and then on again.
copied from Troubleshooting iPhone hardware