No, not using Target Display Mode (TDM) The last iMac that could act as a monitor for another Mac was discontinues in Late 2014.
Carefully read the very restricted system requirments for TDM in this Apple article. In addition to the iMac model limitations, no Mac made after 2019 or running higher than macOS 10.15 Catalina can be the video source for the few TDM-supported iMacs:
Use your iMac as a display with target display mode - Apple Support
You have the option of network screen sharing or, if both computers are running Monterey, Airplay to Mac. Both are laggy however compared to a free-standing external monitor, the most cost effective option for your Macbook Pro.