If it happens when you try to connect your device to ALL wifi networks, I would try this troubleshooting procedure:
Settings>General>>Reset>Reset Network Settings, keeping in mind that this operation also resets Wi-Fi networks and passwords, cellular settings, and VPN and APN settings that you've used before, but no other data are involved.
When done, restart your iPhone, then test it.
If it happens only with your home wifi network, then try and turn off your modem-router, then turn it back on and test your connection and/or check also your modem-router settings.
If the issue still persists, since your iPhone is brand new, have it inspected at your most convenient Apple Store or Authorized Service Provider: Apple - Find Locations - Location Selector
Regards
Giulio