2015 iMac - yes to El Capitan, if that's what you want to do.
Mid 2015 Retina 5k iMac shipped originally with Yosemite, so El Capitan is fine. The newer Late 2015 iMacs all shipped with El Capitan, so you would be good to go with El Cap with a 2015 iMac.
But, not a 2017 iMac - The 2017 shipped with Sierra, so El Capitan is too old, won't install.