I don’t know if this helps or hinders, but I am using a 27” iMac mid-2010 as my display for a 2020 M1 Mac Mini using Big Sur, and connecting the two up with a Morphie USB-C to Mini Display Port cable
https://www.apple.com/shop/product/HN8B2ZM/A/mophie-usb-c-cable-with-mini-displayport-connector
Everything seems to be working relatively OK though I appreciate it isn’t true Target Display Mode, it’s pretty darn close as I’m using the iMac as a target display for the M1 Mac Mini!
Details of the configuration and caveats are here https://discussions.apple.com/thread/252582193 but essentially, the iMac is booted up in High Sierra 10.13.6, the the cable connected to the Mac Mini as it is booting up.
The iMac has the display set to sleep as ‘Never’, and likewise on the Mac Mini but the screen saver works ok but there maybe an impact on the environment and a dent in the wallet over a year!
Anyways, it does show that there is at least one configuration possible out there for the good ol’ mid-2010 iMac 27” to cling onto, which allows it to be used with the latest Adobe upgrades and at M1 speeds.
As for the OP, I suppose it depends upon the MacBook Pro’s thunderbolt connection which may need an adapter at the other end for the 2012 iMac if it doesn’t have the Mini Display Port, but there maybe an appropriate Morphie cable to suit. It would be useful to know, because this and similar questions are cropping up regularly.
I hope this helps, and good luck!