Long back you created a web mail account with gmail services say example1@gmail.com and used this as an Apple ID to sign in Mac system preferences ( the account was initially set up with secondary authentication in which three answers for respective questions , date of birth , rescue mail address and its password , credit card added as optional ) .
After that you signed out the Apple ID and created an Apple ID say example2@icloud.com and started using the Mac .
Now , you can't sign out Apple ID as password is not known to you Sign out of iCloud on your iPhone, iPad, iPod touch, Apple TV, or Mac - Apple Support
If you have always set up iCloud Keychain Set up iCloud Keychain - Apple Support the password for both gmail address and iCloud address can still be found only by an administrator View the information stored in a keychain on Mac - Apple Support
Now coming to your gmail address that is an Apple ID used with iCloud services what is the status on iCloud server https://iforgot.apple.com/appleid#!§ion=appleid
And also link is applicable for Apple ID example2@icloud.com if the id exists a green check mark will appear once you enter the credentials in the link .
Before signing out Apple ID go to appleid.apple.com can you sign in with three correct answers for respective questions and access the account , knowing rescue mail address and its password and using a rescue mail address to reset Apple ID password will work , but most important is answers for security questions and date of birth added in the account , you have to check all these .
If you have all incorrect credentials in records , don't sign out Apple ID from Mac , however a trick is used open system preferences > Apple ID > password and security what is the status do it show 2FA as on or in Mac system preferences >in front of keychain box that should be always checked > if options button is shown it means secondary authentication is set up , if options button is not shown it means account is set with 2FA , you must have working trusted numbers verified in the account
If you want to recover gmail account https://support.google.com/accounts/answer/7682439?hl=en
In case if you also discontinued the trusted number .
The Apple ID created with gmail account say example1@gmail.com was permanently deleted from the gmail server , and if the account was set up with secondary authentication , the administrator can’t sign with iCloud account.
Sign in with rescue mail address in gmail account ( enter the password ) , click on personal info .
Click on edit , and try to add a new trusted number .
And can't further move , the bell icon will shake and stop and if you click on send the code that will go to the old trusted number that is inactive .
Click on more ways to verify , it again prompted to enter rescue mail address and password , Scroll down and click on account recovery icon , then add a new trusted number and click on next , the trusted number will add , the trick was using the rescue mail address that was attached to the primary mail address .
The last way is if you don't have any credentials convert the account into 2FA Use two-factor authentication for security on your Mac, iOS devices, and iPadOS devices - Apple Support
And to change Apple ID sign out Apple ID from system preferences or Change your Apple ID - Apple Support
What to do after you change your Apple ID or password - Apple Support