There are third-party workarounds that might let you use the 27" iMac Pro display as a second display.
The only one that I know about that supports 5K resolution is Luna Display (Astropad). Even if you ran a cable from one Mac to another to help carry video data (tying up two USB-C ports on your MBP – one for the Luna Display and one for the cable), it wouldn't be as good as a real hardware monitor connection. I could be mistaken, but I believe that the refresh rate would be only 30 Hz or 45 Hz, and there might be other issues:
https://astropad.com/blog/step-by-step-guide-how-to-use-your-imac-as-a-monitor/
"Like any product, Luna Display does have limitations and it’s not recommended for high-motion content. For example, I wouldn’t recommend using Luna Display for gaming or video editing.
Since Luna Display is squeezing a 5K display through a USB cable, when lots of motion occurs on-screen (like from video playback or moving a window quickly) the screen can temporarily become pixelated before it renders in at full resolution."
--------------------
Another second-class way of using your iMac Pro as a second display might be to set it up as an AirPlay Receiver for AirPlay to Mac.
Continuity features and requirements on Apple devices - Apple Support
Set up your Mac to be an AirPlay Receiver - Apple Support
I don't think AirPlay to Mac would support the full 5K resolution of your 27" Retina display. Even with its reduced resolution, there could be issues like lags and artifacts, as it tries to pump video updates over your Wi-Fi network. However, because support for this feature is built into your iMac Pro and into the M3 Max MacBook Pro, playing around with it to see if it was "better than a poke in the eye with a sharp stick" (*) wouldn't cost anything.
(*) This was one of the rating levels that an old Mac magazine used. For products that they really didn't like, there was another ratings level: "Please pass the sharp stick."