If you are trying to use the iMac as a monitor for the Mac mini, unfortunately, that setup is not supported by Apple. The iMac cannot be used as a monitor for any of the newest Macs and Target Display mode is no longer a feature of macOS, having been deprecated several years ago.
Please see: https://support.apple.com/en-us/HT204592
Per the link above:
• Your target iMac (monitor) must be using macOS High Sierra 10.13.6 or earlier.
• In all cases the source Mac that you're connecting FROM must have been introduced in 2019 or earlier and have macOS 10.15 Catalina or earlier installed.
However, you might consider a third-party solution, for example: Luna Display or Duet Display, though I can’t speak for the performance of those.
Do yourself a favor, avoid the headache and just budget an extra $100 for a monitor. Yes, they are that inexpensive.