There isn't a built-in way to use your MacBook Pro as an additional display for your iMac. There are a few solutions you can try, though:
If your MacBook Pro and iMac both have macOS 12.4 or later and are signed into the same Apple ID, you can control both devices with one mouse and keyboard. Just drag your mouse to the edge of your display on either of your devices and keep pushing until your cursor appears on the other display.
Other apps like Duet or something similar might be able to replicate the function you're looking for. You can use your iMac as the main computer and connect your MacBook Pro.
iMac (24-inch, M1, 2021) supports one external display using the USB ports on the back of your computer. Depending on your iMac, you might have two or four ports in total, but all models have two Thunderbolt/USB 4 ports.
You can connect any external display, like a traditional desktop monitor or a TV, to your Mac using these connectors. Some displays might require Thunderbolt/USB 4, but most displays should work with any USB port on your iMac, as long as you have the right adapter for HDMI or DisplayPort. Adapters for the Thunderbolt 4, Thunderbolt 3, or USB-C port on your Mac - Apple Support