If your AppleID never "purchased" El Capitan back in the day, then you won't be able to download it using your AppleID now.
If you are able to boot this iMac into macOS, then you can access the various macOS installers using the information in this Apple article (you can access the macOS 10.11 El Capitan installer outside of the App Store using macOS or Windows and any current browser (you will just need to transfer the downloaded installer to the iMac in order to extract the real installer into the Applications folder):
How to download and install macOS - Apple Support
I would highly recommend creating a bootable macOS USB installer using the instructions in this Apple article:
Create a bootable installer for macOS - Apple Support
If you are not able to boot into macOS on this iMac to access the download links, then try booting into Recovery Mode using Command + Option + R which should not require you to authenticate with an AppleID. If the iMac is from Late-2009 or newer, then it may be able to access Internet Recovery Mode using that key combination which may allow you to access a more recent macOS online installer.
Also, it really helps to know the exact model of the Mac and the current version of macOS used. You can get this information by clicking the Apple menu and selecting "About This Mac". If you cannot boot into macOS on this iMac, then enter the system serial number here:
Check Your Service and Support Coverage - Apple Support
FYI, knowing the exact model of the Mac will allow us to know which versions of macOS are compatible with your iMac and the various options available to reinstall macOS.