The following older iMac models can be used as an external display when plugged into another older Mac model.
iMac models introduced in 2011, 2012, 2013, and mid 2014
To use any of these iMac models as an external display:
- The iMac used as a display must have macOS High Sierra or earlier installed.
- The other Mac that you're connecting it to must have been introduced in 2019 or earlier and have macOS Catalina or earlier installed.
- The cable connecting the two Mac computers must be a Thunderbolt or Thunderbolt 2 cable.
24-inch and 27-inch iMac models introduced in 2009 and 2010
To use any of these iMac models as an external display:
- The iMac used as a display must have macOS High Sierra or earlier installed.
- The other Mac that you're connecting it to must have been introduced in 2019 or earlier and have macOS Catalina or earlier installed.
- The cable connecting the two Mac computers must be a Mini DisplayPort cable.
I haven't tried either, but Turn any Mac or iPad into a second display...
https://lunadisplay.com/
Review by NAK005, you may not be happy with it…
Secondary Screen Solution - Apple Community
https://www.duetdisplay.com/
Duet - Remote Desktop, Second Display, Drawing Tablet, and More (duetdisplay.com)