You can't use that iMac as a Target Display, if that is what you are thinking about. Target Display Mode went away when that iMac – the first Retina iMac – came out. Apple later put restrictions on it such that no current iMacs can use any iMac (even an older one) as a Target Display.
See the bad news here: Use your iMac as a display with target display mode - Apple Support
There is a third-party workaround product called Luna Display (by Astropad) that might let you use that iMac as an extra display, but even the Astropad site acknowledges that Luna Display has limitations and is not suitable for high motion applications (e.g., video editing, running games).
You would need a real monitor for that Mac mini even if you decided that you could live the compromises inherent in trying to drive that 5K display in software.