Sounds like you either have a bad Internet connection or a hardware issue with your Mac. Try connecting your Mac directly to the router using an Ethernet cable and any appropriate adapter for a faster more reliable connection that bypasses any hard to troubleshoot WiFi issues.
If you have access to another compatible Qualifying Mac, then you can create and use a bootable macOS USB installer using the instructions in this Apple article:
How to create a bootable installer for macOS - Apple Support
A Qualifying Mac (aka the host) is one which is compatible with the OS installer you are downloading & creating. The host Mac can be currently running any OS. You can use this article to identify which versions of macOS are compatible with various Apple hardware in order to identify a Qualifying Mac to use:
https://eshop.macsales.com/guides/Mac_OS_X_Compatibility
If the Mac you are trying to fix is a 2018+ Mac with a T2 security chip, then the bootable USB installer is not an option unless you already modified the Mac's security settings with the Startup Security Utility from Internet Recovery Mode (Command + Option + R). If this is the case, then you can "Restore" the firmware instead if you have access to another Mac running macOS 10.15+:
Revive or restore an Intel-based Mac using Apple Configurator - Apple Support
You should always provide the exact model of the Mac and version of macOS being used (or last installed) when asking for help because different models & OS may each have their own unique needs.
FYI, after using Disk Utility to erase the drive, you only had to Quit Disk Utility which would have returned you to the recovery mode menu options where you could have easily selected the "Reinstall macOS" option.
You can try running the Apple Diagnostics to see if any hardware issues are detected.