Screen mirroring—which is AirPlay to Mac—that maitaihoa recommends requires the iMac to be 2019 or newer, and Monterrey (macOS12) or later. Is your iMac that new?
Ref: AirPlay to Mac
Even AirPlay to Mac, like network screen sharing and third-party solutions is usually too laggy for a primary display. For a place to dock static windows and palettes, those are fine, but that does not sound like what you are trying do.
The now-deprecated Target Display Mode (TDM) is off the table because current Macs cannot be the video source for the handful of TDM-supported iMacs.
If you need an external monitor, get one. The box-standard models will have no lagging, will be easier to set up, and offer more display options. They also use far less power than a fully running iMac 27.