Unfortunately, your iMac is too new to use Target Display Mode. You could attempt to use screen forwarding software although if that yields sufficient performance depends a lot on what you do. You definitely don’t want to use it for games or video display.
If I were you I’d see that I can get a few bucks off of selling that old iMac and put that towards a new monitor. There are good large monitors for few hundred Dollars these days (Dell 4k for $315 or same with P3 for $245 more). I’m afraid your case once again illustrates what some people say is an inherent problem with the iMac. Why throw away a perfectly good screen just because you need to upgrade the computer?