Which macOS on each Mac? Does each Mac show the other Mac in the Thunderbolt tab of System Information.app?
I tested this now with a Mac mini 2018 (MacMini8,1 ; Sonoma 14.0) and an iMac 27 inch, Late 2013 (iMac14,2 ; Ventura 13.1).
Command-F2 on the iMac shows the Sonoma background after some flickering - then it goes black after a few seconds but sometimes it stops being black. The iMac shows as a display in the Graphics/Displays tab of System Information.app on the Mac mini. The iMac also appears as a display in the Displays preferences panel and as a Sound output device in the Sound preferences panel.
I tried making the iMac the only connection to the Thunderbolt bus but that did not improve things for iMac/Ventura. Seems like Thunderbolt Target Display Mode is broken in Ventura on the iMac. Monterey works better (no flickering or going black) but DisplayPort audio from Mac mini does't work.
I think High Sierra might be the best OS for the iMac to do Thunderbolt Target Display Mode because it allows audio. Except it's currently not allowing Target Display Mode with Sonoma on the Mac mini... I rebooted the Mac mini into Ventura and TDM works with that (with audio). Actually, after rebooting the Mac mini into Sonoma, TDM works (with audio).