I have a 2015 Macbook Pro (Thunderbolt 2 port) for which I would like to use my iMac 2019 (USB-C Port) as an external monitor. What type of adapter and cable should I buy to make this work?
Some newer iMac models cannot be used as external monitor for another Mac.
iMac (Retina 5K, 27-inch, Late 2014) and later iMac models can't be used as Target Display Mode displays.
Nimesh Neema is correct, you cannot use your iMac in Target Display Mode as this feature has not been supported in iMacs manufactured for about the past five years.
However, there are some software options you can investigate, but I have no personal experience with them. Two of these options are listed below:
In summary, they promise to allow users to share their Mac screens on a variety of devices, including other Macs.