No.
You cannot use any recent iMac as a cabled monitor for any other device. Some old Macs made between 2009 and mid 2014 had a feature called Target Display Mode, but it went away in Late 2014 when the first 27" 5K Retina iMac came out, and never returned.
If the LG monitor has multiple video inputs, you may be able to connect it both to the PS5 and to a new Mac (iMac, Mac mini, etc.). I'm guessing that this LG monitor is a 4K one and doesn't have the same Retina pixel density as a 24" M4 iMac, a 27" Apple 5K Studio Display, or a 32" Apple 6K Pro Display XDR. But there are Mac users who are using Mac minis in combination with 32" 4K monitors and like that arrangement.
A M4 Mac mini or M4 Pro Mac mini is very small and so likely would be easy to fit on the desk next to existing stuff, and ones with M4 Pro chips are higher-end than the M4 iMacs as far as the GPU goes. Just throwing that out – in case the issue is that you want a desktop Mac, but there's not enough room on the desk both for that 32" LG, and for a 24" iMac.