If it is an older model iMac without a T2 security chip (2019 & earlier), then there is no need to know or reset the password as long as a firmware password lock has not been enabled. Just boot into Internet Recovery Mode using Command + Option + R to access the online macOS installer for the most recent version compatible with that Mac although some Macs may only boot to the online installer for the older version of macOS which shipped from the factory. The trick is to select the whole physical drive (or Fusion Drive) and erase it using Disk Utility. 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 physical drive (or Fusion Drive item if present) as GUID partition and APFS (top option) for macOS 10.13+. Quit Disk Utility, then select the "Install macOS" or "Reinstall macOS" option.....Do not restart the computer after erasing the internal drive.
Unfortunately a T2 Mac (2020 iMac) will always prompt for an admin password even when booting into Recovery Mode. I don't know what happens if you perform a DFU firmware Restore since that will reset the T2 security chip & system firmware and erase the internal SSD. Afterwards you must boot into Internet Recovery Mode to properly erase the SSD as described earlier & reinstall the OS.
However, it may be worthwhile to attempt to have Apple reset the Mac by showing the previous owner is deceased. If that fails, then try the steps I have presented since there is nothing left to lose at that point.