From the Mac you work on

Open the Second Display menu and turn off the display’s switch. The iMac goes back to its waiting screen, and you can use it as usual. Turn the switch on again to reconnect.

On the iMac

Press Command-Q and confirm. Second Display asks first, because the other Mac loses this display: “Quit Second Display?”

Open Second Display again when you want the iMac to be a display. With Open at login on, it also opens by itself after a restart.

Settings on the display Mac

The waiting screen has a gear that opens Settings. It fades after a few seconds; move the pointer to bring it back.