In addition to @John Galt's advice & information provided by @Servant of Cats........
Personally I would recommend downloading the macOS 10.11 El Capitan installer (@Servant of Cats provided a link to download the macOS installers direct from Apple).....any computer & OS which can access the Internet can be used to download the El Capitan installer DMG file, but you will need to transfer it to the iMac where you can run the .pkg installer/extractor included in the DMG file to extract the real installer into the Applications folder. Then you can create a bootable macOS 10.11 El Capitan USB installer using the instructions in the following Apple article:
Create a bootable installer for macOS - Apple Support
I guess you can try downloading the macOS 12.x Monterey installer since that would be downloaded through the Apple App Store instead of a web browser (would cut down on the work needed assuming you can download stuff from the App Store on that iMac).
I'm recommending creating a bootable macOS USB installer if at all possible before attempting to erase the iMac just in case you may encounter issues with Internet Recovery Mode (Command + Option + R). Otherwise you will need access to another working Mac from about 2007 to mid-2021 to be able to download & create a bootable macOS USB installer (macOS 10.11 to 12.x).