Try booting into Recovery Mode using Command + R which should in theory boot into the online macOS installer for the last OS that was used on this iMac. If you want the newest supported OS, then boot into Internet Recovery Mode using Command + Option + R instead. Unfortunately some Macs will only boot into the online installer for the OS which originally shipped with the Mac from the factory. If you have access to another Mac, then you may be able to create a bootable macOS USB installer.
Once you are booted to the macOS installer, you need to properly partition & format the new drive for use with macOS. You will need to launch Disk Utility and erase the whole physical drive as GUID partition and APFS (top option) if you are installing macOS 10.13+, otherwise if you are installing macOS 10.11 to 10.12 you will need to erase the whole physical drive as GUID partition and MacOS Extended (Journaled). After erasing the whole physical drive, then quit Disk Utility and select the "Reinstall macOS" option.
Make sure to always have frequent and regular backups of your computer and all external media (including the cloud) which contains important & unique data.