Being completely unfamiliar with the answer, I would dare say that it is a legacy of Latin, although I fail to recognize any similarity between Latin declensions and this sort of noun alteration. Is there any source that explores the history of this interesting phenomenon?
To quote @Fabio Turati and his nice description of what I mean by "n-Deklination":
In German you normally decline articles, adjectives and pronouns, but not nouns. Still, some nouns must be declined: in accusative, genitive and dative you have to add an 'n', and these words are said to belong to the "n-Deklination". They are also called "schwache Nomen" (that is, "weak nouns"). For example, let's take "der Name": you say "Wie ist dein Name?" (nominative), but "Sag mir deinen Namen!" (accusative).