Hello to everyone,
after getting all this helpful info through this forum I've decided to contribute something myself.
I had the same issue after
replacing my LG g2 screen. It worked fine before.
The problem in my case was the proximity sensor. It sits behind an oval window between the front facing camera and the light sensor. It has two small lenses, a bigger or the left and a smaller on the right.
If that sensor sits slightly wrong or the front rubber case is missing (I didn't noticed it the first time) or the required pressure from a small rubber behind (it is on the upper black secondary housing with the 7 screws) is not enough to hold it in a fixed certain place, it doesn't work correctly or at all.
When this happens the sensors detects near (meaning you have the device close to your face) and Knock unlocking is blocked. Also when you are making a call the screen goes off for the same reason, so it is easy to notice.
After I noticed and placed the front rubber case from the old screen, it was working, but slowly. It detected quickly the "near" position but it takes several seconds to re detect "far" position.
The final solution was reinforcing the small rectangular rubber which pushes the light sensor and the proximity sensor from behind, with two small pieces of sticker and the problem disappeared.
You can check that through the hidden menu (for my case 3845#*802#), HW Device test, ALC Proximity Test.
It should change rapidly from NEAR to FAR then waving your hand over the sensor.
If not, push firmly with one finger behind the sensor and see then if it is working