Hi,
First of all, as Target Display mode document says, if your iMac is Latina Display, you can't use it as external monitor of MacBook Pro.
You need to get USB-C to Thunderbolt 2 adapter and Thunderbolt to Thunderbolt cable.
https://www.apple.com/shop/product/MMEL2AM/A/thunderbolt-3-usb-c-to-thunderbolt-2-adapter?fnode=8b
https://www.apple.com/shop/product/MD861LL/A/apple-thunderbolt-cable-20-m?fnode=8b
For more info., read Target Display Mode document.
Use your iMac as a Display.
https://support.apple.com/guide/mac-help/use-an-imac-as-a-display-mh30822/mac