Not using Target Display Mode. Target Display Mode went away when Apple released the first 27" 5K Retina iMac in Late 2014, so your iMac is too new to have it. Apple also added restrictions such that no current Mac support using any iMac as a Target Display.
Reference: Use your iMac as a display with target display mode - Apple Support
Your iMac is also too old to act as an AirPlay Receiver for AirPlay to Mac. There may be third-party applications that you can buy to let you AirPlay to it – probably at a maximum resolution of 1920x1080. But the AirPlay Receiver code built into macOS would require an iMac introduced in 2019 or later.
Reference: Continuity features and requirements for Apple devices - Apple Support
That leaves third-party workarounds, such as Luna Display. Luna Display might let you reuse that iMac aa a second display, but you'd still need at least one real monitor (e.g., the laptop's built-in screen), and there are some compromises:
Astropad – Luna Display
Astropad Blog – How to Use Your iMac as a Monitor: A Step-by-Step Guide [2025]
"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."