Using iMac 27" for displaying HDMI output
It can't be done. The 5K iMacs only have MiniDisplayPort/Thunderbolt output, not input, because DisplayPort 1.2 can't handle video at 5K resolution and so it couldn't be used to drive the iMac as a display in Target Display Mode in the same way as some other iMac models. The 5K display on the iMac can only be used with the iMac, because it doesn't have any inputs capable of accepting a 5K input from another source.