I had the same problem and this is how I nailed down the issue.
Try and connect to a different WIFI router or a mobile hotspot. If you have a laptop with Windows 10, you can create a mobile hotspot. if your mobile can't connect, then try resetting the network settings or even the device for a fresh installation. If it cannot connect even then, send it for repairs.
However, If your phone connects fine to the hotspt, your phone is fine. It's the router.
This exact same thing happened with me. You might now ask why the router, every other device connects fine?
True, every other device connects fine. Problem what I think is, this issue started after the december security update, not before that. My 2 cents say that in the december update there was a fix for the KRACK wifi issue. And your router might not have the similar fix.
I ultimately had to change the router to a newer one even thought every other device works just fine. I moved from TP-Link Archer C20i (No KRACK fix) to a Netgear R6120 which has the KRACK fix. Now the phone connects fine.