There is a workaround product called Luna Display, by Astropad, that might let you use that 27" 5K Retina iMac as a second display for the Mac mini.
Even with the Luna Display device occupying one of your Thunderbolt ports, and a separate USB cable running from the Mac mini to the iMac to help. carry video traffic, the connection will not be as good as with a real display. (There is an article on the Astropad site in which they acknowledge that the product has limitations and isn't recommended for high motion content such as video editing and gaming.)
You could look into this – but you will still need a real hardware display for your Mac mini, so I'd suggest that you get one that you would be happy using as your one and only display (if need be). (Or that you get two real displays that you would be happy using as your only displays … you get the drift.)