Why ‘a hospital’ but ‘an hour’

My primary school teachers told me when a word starts with a vowel (a, e, i,…