I echo everything @TheTitOfTheIceberg says.
OP I fully understand your disappointment and your take on it is understandable.
While I don't know, of course, what happened in your specific situation, it isn't as common as everyone seems to think that 'oh it goes to the internal candidate, it's all a stitch-up'. I have been on both sides of this, so I know how it feels. Yes, I have interviewed for roles where on-the-ground information suggested there was an internal candidate who was likely to get the job, and did. I found it disappointing but honestly, I understood it. In my experience, organisations do not 'just appoint' internal candidates, they put them through the interview process, and this is important - to test the candidate, to see how they perform and to evaluate them against other applicants.
In a different scenario, I was an internal candidate for my current role, and had very much proved myself in my work; I was seen as a very strong candidate and people candidly said 'oh of course you'll get it'. But I didn't take that at face value, I know that the interview panel would genuinely give it to the person who performed well on the day. In the event, I did get it - but when I asked for feedback (afterwards I wished I hadn't asked!) I was told that I very nearly didn't - I did a good interview and ultimately shaded it because of my team management experience. The next in line, an external candidate, was apparently excellent on a particular aspect of the role. But this is how it should be.
I've recruited a lot and genuinely, on interview boards, we are looking for the best candidate - and the rules are that it has to be the best candidate on the day. It's no good if they fluff it, and we know them and think 'oh but sure they are usually great at the job'. They must perform on the day. In our area of work, that means giving a good presentation, being very well-prepared and articulate. I hear a lot of people going on and on about perceived unfairness. I think you are better off getting good feedback that you can work on, and leaving that kind of approach aside.