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.
Apple has dropped Target Display Mode support to the 5K iMacs since the bandwidth restrictions when it debuts. There are news mentioning the Intel chip or whatsoever giving further restrictions to the later iMacs and Apple has officially removed TDM support since 10.13.
You may use a pricey workaround like game capturing device to display (and capture) HDMI signal as an app on iMac. It is initially for YouTubers’ use.