This is a hard one to answer. Anyone else feel free to add to my ramblings.
That’s how she’s going to see it, I’m sure, but that was not what he was trying to do. He would have hated himself for being with her against his “code”, and he doesn’t want to do that to either of them.
But yeah…the reason it hurt is…like Cora valuing power over her daughter’s wishes, Robin is putting some abstract ideal first rather than Regina. But the thing is it isn’t an abstract ideal to him—it’s how he lives with himself, and he’s not doing it out of self-interest, he’s doing it because to violate it and be with her would poison their relationship irrevocably.
She had not trusted another adult with her feelings since Daniel, and he’s broken that trust, but he was put in an impossible situation and he did not do it to hurt her. He told her what he did so she would know that she was enough for him, that she was right to trust him, that without this freak accident of fate he would absolutely be with her.
There is a difference between what we mean to say, and how those words are perceived.
And on another note—he is not perfect. She will have to learn to forgive him for how she felt after that conversation, not necessarily because what he did is easily excusable, but because sometimes the people who love us hurt us, and we have the choice to either let it eat up the relationship, or move past it and accept that a hurtful decision doesn’t make a bad person. For better or worse, what Robin did is part of who he is, and she wouldn’t love him if he were somebody else. She has to accept that about him, even if she doesn’t particularly like it at the moment.