You cannot use the iMac as the monitor for the mini. The iMac is an integrated system (just like a mscbook) and unfortunately there is no such feature.
Moreover: it would not help your situation with the iMac 🤷🏽♂️
Haven’t read other solutions, but perhaps a good clean install could help, assuming you have proper backups of DATA. If you aim to do so, i would avoid recovering entire backup and just bring back data (basically Documents, Pictures, Movies, back to their respective folders)
Process:
1) Take an external drive: copy Documents content to a Documents folder, Pictures to a Pictures folder, Movies to a Movie folder)
2) Proceed to clean install of macOS (if you have never done so, please search the topic (before this, please disconnect external drive)
3) Reinstall apps that you aim to use (not those you haven’t used in years)
4) reconnect external drive, and copy back content of your external drive (Documents to Documents, Pictures to Pictures, Movies to Movies and so on).
Test the iMac if possible in between any new app installation.
This is a long process (expect a few hours), but this way you will discard any software issue.
If this does not solve your issue, take the iMac to either an Apple Store or an Apple authorized dealer to conduct a full hardware diagnosis - they have proper tests and usually a fixed (low) rate for this assuming you’re no longer under warranty (likely the case fir a 2019).