It sounds like you want to use the screen of the 27" Late 2012 iMac as a second screen for the 21.5" 2019 iMac.
Your 2012 iMac does support Target Display Mode, using Thunderbolt input. Unfortunately, taking advantage of that feature is not very feasible.
- Apple placed restrictions on Target Display Mode such that the iMac acting as the "display" has to be running High Sierra or earlier. That might mean downgrading, or dual-booting, the 27" 2012 iMac.
- Apple placed restrictions on the other Mac so that it has to have a hardware release year of 2019 or earlier and has to be running Catalina or earlier. Your 2019 iMac can run Sequoia (which is still one of the "most recent 3"), and it would not be worth downgrading to Catalina just so that you could use the old iMac as a Target Display.
- TDM on a 2012 iMac requires Thunderbolt input. You would need to purchase a $50 Apple Thunderbolt 3-to-2 adapter and a hard-to-find, $30+ Thunderbolt 1/2 cable (not an inexpensive USB-C to Mini DisplayPort adapter cable).
I would suggest saving the $80+ you would have to spend on specialized Thunderbolt cabling – and putting that money towards the purchase of a good 27" 2560x1440 ("1440p, 2.5K") or 27" 3840x2160 ("4K") monitor.
You can get some decent 27" 4K monitors with IPS panels and 100% or near-100% coverage of sRGB for $300 – $400 USD. Your Mac would probably be able to run them in Retina "like 1920x1080" mode (large print, but taking advantage of the 4K resolution for increased sharpness) or Retina "like 2560x1440" mode (similar size print to the print on your 27" 2012 iMac, with somewhat more detail).
A further bonus is that when it was time to upgrade to your next Mac, you could use that 27" 4K monitor with the new Mac.