These kinds of things happen to everybody - and feeling like you were passed over, or worrying that it's because of your conduct and performance is a normal response that many people have. Just don't let it become habitual, because you may feel disproportionately passed over even if you rationally understand the their reasons.
Monstar has offered several excellent explanations for the business side of things and suggested how you could approach the issue-at-hand professionally. I think it is important for you to address your feelings on the matter as well, and you need to involve your supervisor to do so effectively. The appropriate venue is a one-on-one with your supervisor that you schedule specifically to discuss the decision.
I get serious bouts of impostor syndrome, so I sometimes feel strong emotions over these kinds of business decisions and they make me worry about my performance. That worry has (in the past) impacted my performance negatively. Re-calibrating my emotional thermometer helped me enormously.
I do this by asking specific questions about the decision-making process and what the company hopes to gain from the change. It also helps if I state that I feel attached to the project, and that I know that may be irrational. I also tend to ask if my performance was a factor in the decision-making process. This helps in a few ways:
Personally:
- I get to check my assumptions, separating feelings from facts.
- If the decision was simply bad (ex., a higher-up flexing their ego), I no longer attribute it to a failing of mine.
- In one such conversation, my then-manager mentioned 'watching my tone on code reviews'. In hindsight, I was frequently snarky to a junior team member. My manager's comment helped me mend fences and avoid a termination meeting.
Politically:
- I get better info on the decision-making processes and develop a better feel for the political landscape.
- I can (selectively, and within limits that I now know and understand) exert influence over the execution of decisions.
- I'm viewed as more open to feedback and trusted with more sensitive projects.
- I'm consulted more often, because I've learned to not give feedback when it is too late.
Consider carefully what you'd like to get out of the conversation. If you simply want recognition of your feelings or special consideration (your supervisor consulting you on every decision that may impact you), then the discussion will not go very well. You can't expect or demand either, and an agitated discussion about this will impact your standing.
I still get angry about boneheaded decisions. But even if I have strong feelings, I try to to keep the discussion level-headed and constructive. I used to give feedback on decisions after they were made, out of spite over being kept out of the loop. That team did not see me as a problem-solver.