I definately feel you need to talk to someone about this!!! I think you have a view of sex as something bad and wrong, and having random sexual encounters is a form of self punishment because you are unhappy in other areas of your life.
First and foremost, what you did was not wrong, and its not particularly uncommon either (the sex, not the punishing thing), you need to find out whats making you feel you need to self harm in any way, and discuss your emotions, whats going on in your life, and your attitudes to sex with a professional, its the only way you'll be able to work these things out. Visit your GP for a referral, or contact your Student advice line at Uni, most of them have these now
Good luck with everything!!