Target Display Mode using 2019 MBP and 2012 iMAC
Did you use a 'Thunderbolt' or 'Thunderbolt 2' cable to connect the two macs?
Also judging by your description the iMac has Mojave installed whereas TDM would work only on an iMac with High Sierra or below.
For reference please follow this official Apple article: https://support.apple.com/en-us/HT204592