Why a university not An university?
Much like how the letter "y" acts as a vowel in words (wherein they behave as an "i" sound), such as in yvonne, or city, the letter "u" can act as a consonant in words too. Keep in mind that the phonetic definition of vowel and consonant is how the sound is produced in terms of obstruction of the vocal tract. The exact term for this particular pronunciation of u is a palatal approximant, which is for all intents and purposes, a consonant.
I hope this made sense :/
Ah sorry! I misread your question and therefore gave you a fudged answer. It's consonant "sounds" and vowel "sounds" that determine "a" or "an" choice. So I would say "a university" for the same reason one said say "an hour". ;)
Think I need a coffee
The rule is very simple. "A" and "an" have exactly the same "definition" as the indefinite article.
"A" is for words starting with consonants and "an" is for words beginning with vowels.
I imagine this rule came into being so as to make speech flow better.
Try saying "A apple". It's weird isn't it. "An apple" is much more natural and smooth.
So, since U is a vowel, "an university" is correct and "a university" is wrong.