Unfortunately M1 Macs don’t support connecting to iMacs in TDM. The Mac that’s using the display needs to be running High Sierra or lower.
Target display mode is a feature available with certain older Mac models.
support.apple.com
Also TDM does use the GPU of the target iMac, so if it’s cooked, it won’t work either. Sorry mate.