Try booting into Internet Recovery Mode using Command + Option + R to attempt to access the online macOS installer. Theoretically this should access the online installer for the most recent version of macOS that is compatible with your Mac, however, some Macs may only access the online installer for the version of macOS which originally shipped with the computer from the factory regardless of the keys used for booting.
Otherwise you need access to another compatible Mac in order to create a bootable macOS USB installer. Generally you need:
- macOS 12.x -- model 2015 to mid-2022 (assuming a 2015 iMac)
- macOS 11.x -- model Late-2013 to mid-2021
- macOS 10.15 -- model 2012 to mid-2020 (Intel only)
- macOS 10.13 -- model Late-2009 to mid-2018
- macOS 10.11 -- model 2007 to 2015 (assuming a 2015 iMac)
You can confirm the other Mac is compatible with the OS by using the information in the following article since the model designations listed are just generalizations:
https://eshop.macsales.com/guides/Mac_OS_X_Compatibility
These are your options for reinstalling macOS. I guess you can try erasing the "Macintosh HD" volume as well just in case there is something wrong with it. Normally I recommend erasing the whole physical drive, but currently you are likely booting into the local Recovery Mode to access the Sierra installer.
FYI, more than likely the internal Hard Drive is failing which is why you are getting this error. If the system was running very slow before being erased, then it makes this possibility even more likely. You can try running the Apple Diagnostics to see if any hardware issues are detected, but unfortunately the diagnostics rarely report any issues.
You can also try installing macOS to an external drive to see if that makes any difference. I would recommend booting into Internet Recovery Mode using Command + Option + R to bypass the potentially damaged local recovery mode located on the internal Hard Drive. If you can install & boot macOS from an external drive, then it will be possible to check the health of the internal Hard Drive.