There's at least one hardware kit and there are instructions on how to buy the kit, open the iMac up and do things comprehensible to more technically inclined people than I to make it work. An involved task. Here's someone's explanation of doing it:
https://ohmypizza.com/2023/04/converting-a-5k-imac-into-an-external-5k-display
There's a product called Luna Display, and it comes in various forms. One has a direct Thunderbolt connection. Bottom line, I wasn't won over from reading about it. Pay attention to refresh rate when you look at some of these options. Here's a page with somebody talking about using Luna Display.
https://astropad.com/blog/step-by-s...kkHpOtaFP-0hK4VT-oO5AnmHKizJZiwPHuIIiSCoDEwVC
It makes for interesting reading, but I think the conclusion you'll eventually reach is that you'll plan to get a new monitor with your next system.