Connecting to WiFi - spinning wheel
The spinning wheel in the Settings, Wi-Fi screen when attempting to connect an iPhone to a WiFi network can be the result of the iPhone not obtaining an IP address.
In my case this was because the isolated Wifi network (created to provide connectivity to a tank water level monitor in a seaside bach with no internet connectivity) wasn't providing one. Setting the access point and the iPhone to fixed private IP addresses in the same subnet resolved the issue.
So this is more of an answer than a question.
iPhone 12, iOS 16