Connect MacBook Pro 2015 to iMac 2015 with HDMI?
Target Display Mode needs DisplayPort or Thunderbolt. It cannot use passive HDMI adapters or ones that don’t support active HDMI to DisplayPort. 


https://www.amazon.com/DisplayPort-Adapter-FOINNEX-Converter-Compatible/dp/B07G796JF8/
https://www.amazon.com/StarTech-com-HDMI2DP-DisplayPort-Active-Converter/dp/B004I6IYSM/


Warning, that the apple link only lists DisplayPort in for some models of Mac. Be sure you can return anything you buy if you’re not sure it will work or have the seller or manufacturer confirm your specific Mac and use. 

Source : Apple KB - Use your iMac as a display with Target Display Mode