Back in 2018, helped a customer fix a software glitch with their iPhone wifi, where the wifi switch often wouldn't turn on. Or, the wifi would appear to be on and connected to the network on the main page of the settings app, but tapping wifi would reveal that the wifi was actually off. Originally he suspected that the issue was hardware, until the wifi problem persisted after upgrading to a new iPhone XS.
Here's his description of the problem, to help see if it applies to you:
I was hoping you would be able to help me with an issue I've recently encountered where my phone has trouble connecting to the WiFi. Often times it appears as if my WiFi is permanently off and I have no way of switching it on. For example, if I goto Settings > Wi-Fi, I will see that my Wi-Fi is slider is set to off. If I try to slide it to on, it just slides back to grey/off as soon as I let my finger off.
This was happening on my iPhone 7, and when I recently switched over to a new iPhone XS, I am getting the same issue (which leads me to suspect it is software related). I am running iOS 12. Sometimes if I restart my phone, the problem corrects itself but after a period of time, I encounter the same issue again. Have you ever encountered an issue like this before?
When I tap on Settings and look at the row for 'Wi-Fi' (just underneath 'Airplane Mode'), I do see the name of my home WiFi network displayed so it seems to recognize it. However, it's not actually connected to the WiFi network. When I tap into the 'Wi-Fi' row, that's where I see that my Wi-Fi slider is set to off and attempting to slide it to on just doesn't work. However, I notice sometimes that if I just leave my phone alone for some indeterminate period of time (could be an hour or more), it sometimes randomly connects to the Wi-Fi by itself.
Here are the usual tricks, which I always recommend you try first if you're having iPhone wifi glitches:
Open the Settings app, and turn on Airplane Mode. Wait 10 seconds, and then turn Airplane Mode off.
Open the Settings app > General > Reset > Reset Network Settings. This will purge your existing saved wifi networks and passwords and your other saved wifi settings.
(New, added September 30, 2020 for iOS 14) We're seen a few cases where a full settings (not contents) reset will fix the wifi. To try this, open the Settings app and choose General > Reset > Reset Settings. If this works for you, please leave a note in the comments!
If none of these work, next I highly recommend contacting Apple Support. There used to be more software causes for WiFi problems, but since mid-2020, nearly all of the WiFi issues I've seen are hardware problems, and need Apple's intervention to diagnose the problems.
Rarely, I still see a WiFi problem where the problem is fixed, but then problem shortly returns. Or, I see a WiFi issue where the WiFi works on a new/replacement iPhone, but restoring a backup of the old iPhone brings the problem to a new iPhone. These are usually problems with wifi entries in the iCloud keychain (which you can edit using macOS Keychain Access app if you have a Mac!) but, these problems are rare now in iOS 14 and iOS 15. If you do think you have this kind of problem, leave us a comment!