Apple used model ID iMac15,1 for
- iMac (Retina 5K, 27-inch, Late 2014)
- iMac (Retina 5K, 27-inch, Mid 2015)
Target Display Mode went away when the 2014 one – the first Retina iMac – came out. Neither of those Macs have that feature. See: Use your iMac as a display with target display mode - Apple Support .
Your Mac is too old to be an AirPlay Receiver for AirPlay to Mac, a lower-quality connection method. See the AirPlay to Mac section of: Continuity features and requirements for Apple devices - Apple Support . There might be third-party applications for sale that would let you turn the iMac into the equivalent of an AirPlay Receiver, using the older AirPlay v1 protocol, with a limit of 1920x1080 for the resolution, but I really don't think that this would be any sort of satisfactory way of reusing the iMac screen.
There is a third-party workaround product called Luna Display that might let you use that iMac as a second display, but the Astropad site says that Luna Display has limitations and is not recommended for high motion content like gaming and video editing. See: Astropad – Astro Blog – Use Your iMac as a Monitor: A Step-by-Step Guide [2025] . I can see the attraction of the product given that 27" 5K standalone monitors are still relatively scarce & expensive, but there are now third-party ones out, or coming out, that might go for as little as $800 to $950 (street price), vs. $1599+ for the nice Apple one.
I would suggest buying a standalone monitor for your Mac mini that you would be happy to use as your one and only monitor. Don't plan on using that 5K iMac as your main display – if you can even use it at all.