There are two native(ie Apple) ways of doing this, unfortunately your 2015 iMac falls outside of both requirements.
You can use something called Target Disc Mode on iMacs built between 2011 and late 2014:
Target display mode is a feature available with certain older Mac models.
support.apple.com
iMacs and iMac Pros later than 2019 can be used using Airplay:
Want to use your iMac's awesome screen as a monitor for your MacBook or Mac desktop? If you're using a newer iMac running macOS Monterey, it's easy to use AirPlay to mirror or extend your screen to an iMac. For older iMacs running High...
www.wikihow.com
You could use something called Luna Display or Duet Display, but you'll have to pay for it:
This in-depth guide covers how to use iMac as monitor with Apple's target display mode, with third-party software, and more.
9to5mac.com