Confronting her about it was a mistake. As it shows you're butt hurt. Which will indicate to her that you lack emotional strength.
Also, she's just 1 young woman. What about the hundreds or thousands of other lovely young women at your uni?
I strongly suspect that there's more to it than this other guy saying he was lonely and nobody wanted him. If he said that in a serious way he was acting in a rather unattractive way. If he said it in a joking / self mocking kind of way then he was acting in an attractive way. Or if he said it seriously and then went on to interact with her in an attractive way, then that's why she slept with him and not you.
Usually you don't get women into bed with you by being ultra nice. Nor by trying to be her best friend.
For future reference, if you're talking with a woman and another guy butts in, there's a couple of ploys you can use:
1. Ask straight away "Do you 2 know each other?". If he says "No", you say "Just give us a minute" and carry on talking with her, maybe moving her to a different location. If he says "Yes", you ask how and then if they're not boyfriend and girlfriend say "Just give us a minute"
2. Play on the fact that he's trying to chat her up. EG "Is that your best pick up line?" with a smile on your face in a friendly tone of voice. Or "Hey, I think you're the sort of guy that's great at picking girls up. Come on, show us how you do it. Show us your really cool pick-up routine..."
You should aim to be the emotionally and mentally strong guy. That talks to everyone and anyone around campus and in your halls in a positive and enthusiastic way. That keeps things light. That laughs a lot and others laugh a lot around him. Also be the sort of guy that takes the lead in escalating to sex in a socially calibrated non rapey way.
And also don't forget to do proper revision for your end of year exams. So that you're the sort of guy that handles exam pressure well.
I have one or two amusing anecdotes I can trot out about large penises. A bit of joking around was the sort of thing to do when she mentioned his size.