How do I stop my phone from turning off the display whenever I put my finger over the phone speaker?

Solution 1:

In this case, it was just a bug. All you need to do to fix this is to restart your iPhone and it should be fixed. Thanks to Apple support.

Solution 2:

The proximity sensor next to the front camera/speaker engages when it believes the device is being held to your face. Holding your finger over it causes the same effect.

There is no way to disable the proxmity sensor.