If it is not a firmware password lock, then you can try booting to the macOS installer (Recovery Mode using Command + Option + R, or USB) and using Disk Utility to erase the whole physical disk (or Fusion Drive if it has a Fusion Drive). Within Disk Utility you may need to click "View" and select "Show All Devices" before the physical drive appears on the left pane of Disk Utility. Erase the whole physical drive (or Fusion Drive) as GUID partition and MacOS Extended (Journaled).
As long as there is no firmware password lock and the device is not locked by FindMy, then you should be able to wipe the iMac & install an OS of your choice (macOS 10.6 - macOS 10.13).