Sign out of the old account if necessary; sign in with the new one.
Sign out of iCloud on your iPhone, iPad, iPod touch, Apple TV, or Mac --> https://support.apple.com/HT208242
If another Apple ID is signed in you may need to enter the password for that ID to sign out of that ID first.
Click on this link to learn how to 'Sign in with your Apple ID' --> https://support.apple.com/HT204053
Since this is an "ex" you may wish to consider more thorough ways of removing items associated with the other ID. There's multiple levels of doing this:
How to erase your iPhone, iPad, or iPod touch
"Learn how to wipe information from your iPhone, iPad, or iPod touch and restore your device to factory settings." Without using a computer. Does not reinstall iOS.
Click here --> https://support.apple.com/HT201274
iCloud: Remove your device from Find My iPhone
https://support.apple.com/guide/icloud/remove-a-device-mmfc0eeddd/icloud
• "If you forgot to turn off Find My [device] before you sold or gave away your iPhone, iPad, iPod touch, Mac, or Apple Watch, you can turn off Activation Lock using Find My iPhone on iCloud.com . "
My biggest concern would be if the phone was signed into Find My with the other ID. That will require the other ID or person to remove it unless you can convince Apple to reset it.
iCloud: Remove your device from Find My iPhone
https://support.apple.com/guide/icloud/remove-a-device-mmfc0eeddd/icloud
• "If you forgot to turn off Find My [device] before you sold or gave away your iPhone, iPad, iPod touch, Mac, or Apple Watch, you can turn off Activation Lock using Find My iPhone on iCloud.com . "
If necessary and you are willing to wait, Apple can completely reset a device if a person can provide sufficient evidence of valid ownership. Do this online at: Activation Lock support request - https://al-support.apple.com/#/additional-support Apple says, "Proof of ownership documentation is required," but does not state what currently constitutes proof. Prior to this new online service Apple typically required the original receipt issued by Apple or an Apple Authorized Reseller and documented provenance (so typically it would be the original owner who does this, or a descendant with legal proof of ownership).