Target Display Mode is only available with specific combinations of Macs running certain versions of macOS. The Target, to be used as a second display, must be an iMac introduced between 2011 and mid–2014, or a 24– or 27–inch iMac introduced in 2009/10. That must be running no version of macOS later than 10.13 High Sierra.
The Mac connecting to that must have been introduced in 2019 or earlier, and also be running macOS 10.15 Catalina or earlier. Connecting the two requires a Thunderbolt or Mini DisplayPort cable depending on the models. Apple provides full details at www.apple.co/3H2LQZI.