I know this is quite old, but if anyone lands here, I had the same problem, my iPhone suddenly had issues transitioning between 4g and WiFi. So if I left my WiFi and came back into it, it would take about 2-3 hours before it would connect again.
I did absolutely everything people recommend: turned it off and on, backed it up and restored the whole thing back to factory settings, changed every possible setting. Nothing worked, then I popped out the sim and my phone instantly connected to WiFi. I ordered a new sim and it works fine now.