Good morning!
To see the very restricted hardware and system software requirements for what you are attempting—Target Display Mode—please see this Apple tech article:
Use your iMac as a display with target display mode - Apple Support
1) Your video source—the Macbook Pro that appears to be running macOS 11.7—would require its system be downgraded to 10.15 Catalina to be the video source for a TDM-support iMac.
2) "....hook up to 21” iMac purchased in 2011/2012. ...." Can you be more specific by doing "About this Mac..." on the iMac? 2010-2011 represented a change in TDM requirements and a purchase date does not necessarily covert to the sub-model name which Apple uses to establish compatibility.
Example of where to find SUB-MODEL from "About this Mac..."

- A 2009 or 2010 iMac had to be a 27-inch model to works with TDM. 21.5-inch models from those years were not supported.
- Starting in 2011, TDM support was added to the 21.5-inch iMacs but discontinued with the 2014 models.
- The iMac, if supported, must be in normal operating condition. You are using the entire computer with TDM, not just the display.
For an iMac with a mini-display port, the typical (and successful) connection arrangement is:
video source from 2015 Macbook Pro > thunderbolt cable > thunderbolt to mini-display port adapter > 2011 iMac
NB: Please consider a free-standing external monitor instead. The last time I checked, the required cabling and adapter to do what you want could cost between US$60 and US$90! 😳 Also you would not have to downgrade the OS on your Macbook Pro to use a regular external monitor. Some TDM setups are limited to mirrored only; if you need extended desktop combined with lower power consumption, get the external and wish the iMac a happy retirement.
You are doing archeology with TDM. Apple began its deprecation in Late 2014 and threw the last shovel of dirt in its face in early 2020. Dr. McCoy said it best:
