Hi there! I'm a guy, and I can try to speak to this from my perspective. That being said, take it with a grain of salt if it doesn't resonate with you.
There have been a couple occasions where my wife has caught me doing the same thing. It is very rare, and I know I'm not the kind of guy who stares, wants to look/stare, does it intentionally on a regular basis. However, I absolutely understand why it hurts her/you the way it does. When you love someone, you want them to only have eyes for you and want them to be attracted only to you. While try as we might, no matter who we are, this type of situation inevitably happens. For someone to deny attractions to other people is a big fat lie, in my opinion. We are human, and noticing these attractive attributes others have - emotional, physical, mental, etc. - is a part of the human condition.
Don't get me wrong, I am not in any way excusing or condoning staring at other people when we find them attractive, especially in the context of a romantic relationship. However, I do know that things like glancing at someone/something attractive can become even more amplified when we are in a state of anxiousness, insecurity, or conflict with our partner. When we're not in a good place, it is easy to catastrophize the meanings of actions or words and use them as ammunition against our partner.
I think what can be helpful is reminding yourself of your own worth. If you know your partner loves you and believes you're attractive, even if they found someone else attractive in that moment, try and let that be enough. We are all imperfect and will do imperfect things, and yet we keep coming back to our partners because, at our core, we love them and they love us.