See the article https://support.apple.com/en-in/HT201356
In your iPhone an Apple ID say example1@gmail.com is signed in , also you had created a passcode so its not possible to access the iPhone for any one without your permissions .
For Apple ID created say example2@icloud.com did you shared the credentials with ex like password , how is the Apple ID created with two factor authentication or secondary authentication in which three answers for security questions , date of birth , rescue mail address and its password .
If the credentials like Apple ID address is shared between you and ex and the person is using say another Mac or iPhone and that mail address is accessed from web account or through IMAP account in Mac , if you change password from a browser the second person will get a notification that password is changed .
So it depends upon you to change all credentials like https://support.apple.com/en-us/HT201363
https://support.apple.com/en-us/HT204164
https://support.apple.com/en-us/HT201356