Could be a software app blocking activity, could be a bug in macOS, could be bad Wi-Fi hardware in the Mac, or could be Wi-Fi interference in the vicinity of the Mac. Could also be the Wi-Fi router.
Restart both the Mac and the Wi-Fi router, and try again.
Reboot the Mac into Safe Mode, as see if the problem persists. Safe Mode rebuilds various caches, and disables some of the more problematic add-ons.
… How to use safe mode on your Mac - Apple Support
If you have add-on security apps, add-on cleaner apps, add-on VPN client apps, add-on anti-malware, remove all that per the vendors’ instructions, restart, and try again.
Run hardware diagnostics.
Failing the above, download and run EtreCheck, and share the report to the clipboard. Then open a new reply here, and press the
Additional Text button (that looks like a printed page) to get a text input box big enough to paste the hardware and software configuration report here, and post that report here.