You have the 27 inch iMac 2012? You are using the Apple Thunderbolt 3 to Thunderbolt 2 cable? Can each Mac see the other Mac in the Thunderbolt tab of System Information.app?
Thunderbolt Target Display Mode (TTDM) still works for me to a iMac (27-inch, Late 2013) running Monterey 12.4 (with OCLP). The other Mac is a Mac mini 2018 also running Monterey 12.4.
https://forums.macrumors.com/threads/2011-imac-graphics-card-upgrade.1596614/post-31109030
When I press Command F2, nothing happens if my Sonnet Echo Express III-D containing a PCIe serial port card is connected. If I disconnect that, or boot with the Mac mini already connected, then TTDM works (but the serial port card doesn't?).
If the screen goes black, then you know it's doing something. Sometimes I need to press Command-F2 a couple times to make the screen not black. Another option may be to use the Enable Display option in SwitchResX. Usually I need to press Command-F2 a couple times to stop TTDM.
Older Thunderbolt iMacs may have different behaviour?
https://forums.macrumors.com/threads/2011-imac-graphics-card-upgrade.1596614/post-31109756
Did you try booting with no other Thunderbolt devices connected? Booting with the Macs already connected?