The gowns and mortarboards graduates wear are descended from the garments of the middle ages, but the distinction between ecclesiastical and civilian garb was not that great, especially for the lower clerical orders. The hooded sack cloth that we usually associate with the middle ages was only for certain religious orders or those who could not afford something nicer. When education and formal universites started to flourish in western Europe, they were for the clergy, the rich (merchants) and those of the ruling class not likely to inherit the throne/dukedom/estate. Academia has always been a refuge for the useless. As members of a certain social level, and having certain rights and responsibilities (if nothing else, they could read the king’s decrees to those annoying peasants, or figure out how much tax to bleed from them), scholars were expected to dress a certain way. The mortar board and gowns were like the business suit of today.
If I remember correctly, the bachelor’s degree (or lower, I guess) besides the gown, gets the mortar board, the master’s degree gets the mortar board and a separate hood, draped over the shoulders, and those who avoid a real job long enough for a PhD, get a hat to replace the mortar board. (By the way, you have to pay for the hood or hat yourselve - after spending $150K - $180K to reach an advanced degree - no freebies).