No, not using Target Display Mode (TDM). The last iMacs that could act as an external monitor for another Mac via TDM were discontinued in Oct 2014.
The limited hardware and software requirements fo TDM are in this Apple article:
Use your iMac as a display with target display mode - Apple Support
You can try network screen sharing but it is sluggish.
Share the screen of another Mac - Apple Support
Frankly, a free-standing external monitor is the best and most cost-effective option and allows extended desktop; TDM only allows mirroring as does screen sharing.