iPhone 8 totally freezes when trying to connect to WiFi
Try to solve it with:


resetting network settings
trying wifi networks with different settings
reinstalling iOS


Resetting network settings:

Settings > General > Reset > Reset Network Settings

Trying wifi networks with different settings:


try to disable bluetooth, airdrop, and cellular data first (try to activate wifi while in airplane mode)
try wifi networks with different settings like frequency, encryption, name, device vendor, internet connected/disconnected
start with unecrypted wifi, disconnected from the internet


Reinstalling iOS:


make a full backup to iCloud
make a full local iTunes/Finder backup (don't rely on single backup type)
(Tip: use an encryption - more data are backed up)
reset the phone to DFU mode
restore iOS with iTunes/Finder
setup as a new iPhone
connect to Wifi; did it help?
if the phone is now stable, proceed to reset the user data from settings and restore your backup
connect to Wifi; still stable?