The newest OS your 2012 iMac can be upgraded to is macOS 10.15.7 Catalina.
But It can also run 10.11 El Capitan, 10.12 Sierra, 10.13 High Sierra, or 10.14 Mojave.
❗️ – IMPORTANT – If you decide to upgrade to Catalina from 10.14 Mojave or earlier, your older 32-bit apps & drivers won’t work in Catalina or newer! They must also be updated or replaced. Use the free utility Go64 app from St. Claire Software to check your current apps.
Before you think about wiping this Mac, do two very important things:
1) backup any data you want/need to save onto an external drive. You can use Time Machine or even just click and drag your stuff.
2) Create a bootable USB installer for the macOS version you want to install. If all else fails, you will have that to use to reinstall an OS and get the Mac up and running again.
Create a bootable installer for macOS - Apple Support
With those tasks done, you can now reset the Mac by following this guidance:
• You need to startup the Mac from macOS Recovery mode to erase and reformat the startup disk.
Use Disk Utility to erase an Intel-based Mac - Apple Support
• Then you'll reinstall macOS. This is where things might get dicey and why should create and have a bootable usb macOS installer at hand.
How to reinstall macOS - Apple Support