Some of the older, non-Retina iMacs supported Target Display Mode. This included some Thunderbolt-equipped Macs that you could use as Thunderbolt monitors. I believe that the latter were old enough that all of them would have used the old-style "Mini DisplayPort" Thunderbolt connectors.
None of the iMacs with Retina screens support TDM.
The converter you used (probably USB-C to HDMI; not Thunderbolt to HDMI) would not have worked, because it would have converted to HDMI, not from HDMI.
Even if you bought an Apple Thunderbolt 3-to-2 adapter, and made a Thunderbolt-to-Thunderbolt link between the new MBP and the old iMac, it wouldn't be supported and probably wouldn't work. It appears that Apple now requires the Mac that is the "computer" (in your case, that would be the MBP) to be from 2019 (??) or earlier and to be running macOS Catalina or earlier. Which kind of closes the door on using TDM even if your iMac is one of those that is old enough to support it.