The historical origins of the "age of majority" mostly have to do with the age at which a boy was considered physically fit for combat, particularly in the context of when a boy was considered fit to be a knight.
For a long time in the early-medieval European context, fifteen was considered the age of majority when boys could be brought to fight in the army, but around the 11th and 12th century, it shifted up to 21. This is largely attributed to the fact that armor became heavier and more complex, weapons became bigger, and the increased use of horses by knights in combat. All of these factors meant that being a competent knight required more strength as well as more skill, and therefore, more training. The Magna Carta established By the time of the Magna Carta, 21 had been established as the legal age of majority in England in regards to when the son of a knight/lord could himself obtain his knightood. Other legal privileges and responsibilities became tied alongside knighthood and the age of 21, such as the ability to claim one's inheritance without dispute.
Source: T.E. James. "The Age of Majority" The American Journal of Legal History Vol. 4, No. 1 (Jan., 1960), pp. 22-33
When and where the shift moved down to eighteen happened, I'm less certain of, although I can speculate that it also had to do with military service by piecing together what I know about the history of voting age in the US. During WWI, WWII, Korea, and Vietnam (as well as possibly earlier times), men were drafted into the army at the age of 18 even though many of their other legal "age of majority" rights such as voting and drinking were held at the traditional age of 21. This created the controversy during Vietnam that led to voting age being lowered to the same age as military service, so that men who are compelled to join the military at least have the legal right to influence the policies that may send them to war.
OP, can you specify which country or other legal jurisdiction you're asking about? The USA? thx
Also, this would be worth x-posting to a sub that specializes in law for that jurisdiction
Searching the archives is always good when you ask about something that isn't terribly obscure.
These two threads are good places to start: https://www.reddit.com/r/AskHistorians/comments/34wjo9/how_did_the_maturity_age_came_to_be_18_years_old/ https://www.reddit.com/r/AskHistorians/comments/1pvb4o/when_did_18_years_old_become_the_general_legal/