PixelPhotography wrote:
Do you know which cable i need to have for this?
There's no cable that will turn one of those iMacs into a hardware monitor for the other. I believe that rkaufmann was suggesting that you buy a standalone external monitor to use with your iMacs. Like the 27" Apple 5K Studio Display (if you have the $$$$$), or a 4K display (if you don't, or if you are in the market for an Eizo-level monitor, and are willing to give up some resolution in return for high-end color calibration / accuracy features).
P. S.
Apple once had a feature (Target Display Mode) to allow reusing an iMac's display. It went away about ten years ago when the first 27" 5K Retina iMac came out, and it didn't return even after the introduction of Thunderbolt 3. Then Apple added restrictions to keep newer Macs from taking advantage of older iMacs that do support TDM.
There are workaround solutions that you could investigate, such as Luna Display (Astropad) and Duet Display, but even if you run a cable in conjunction with them, you're not going to get a first-class hardware-accelerated video connection.