The 'u' in unicorn sounds like 'y' — a consonant sound
'A' vs 'an' depends on the SOUND following, not the letter. Unicorn starts with a 'y' sound (yoo-nicorn). Same reason: 'a university,' 'a European.'