Replacing the hard drive in these macs requires separating the display. Possible but a delicate operation. https://www.ifixit.com/Guide/iMac+Intel+27-Inch+Retina+5K+Di...
I’d just throw a thunderbolt or usb3 SSD in a port instead. I boot off a USB3 SSD on my Mac mini and that seems to work fine, despite not being quite as good as an internal or TB drive would be.