That iMac doesn't support Target Display Mode. Target Display Mode went away in Late 2014 when the first 27" 5K Retina iMac came out, and never came back. No Retina iMac has it. On top of that, Apple added restrictions so that no recent Mac supports using ANY iMac as a Target Display.
There is Luna Display (Astropad). It's not as good as a real hardware connection to a standalone 5K monitor, but it might be the only game in time for reusing that 27" 5K iMac as a second display – for fairly static content – at its 5K resolution.
All of the 27" 5K (5120x2880 pixel) monitors out there (Apple, LG, Samsung) are very expensive. The Apple one is almost as much as what a 27" 5K Retina iMac that included the keyboard, mouse, and computer as well once cost. But you can can get good 27" 4K (3840x2160 pixel) third-party monitors for much less money.