So, basically, medieval European states did not maintain permanent, standing armies (Byzantines excepted). They raised armies for a purpose and then disbanded them when that purpose no longer existed (or they ran out of money). As such, young men didn't join the army for a career or a multi-year hitch; they answered the levy and served for one campaign, or they volunteered to spend a year in the Calais garrison, or they joined a lord or king's retinue and went to war with them. In this context, a rational chain-of-command wasn't really possible. Who was in charge of the army, and in charge of its sub-parts, depended on who showed up.
The particulars of military organization varied with time and place. I mostly do 11th-12th century Normandy and Norman England, so I'll confine myself there. We know the most about the knights, who fought in a tactical unit of 15-30 riders called a conroi. These men were very frequently neighbors and the servants of the same lord and were usually well used to working together. There do not seem to have been any formal units above this level. We know much less about infantry organization.
For more on the subject, I encourage you to have a look at this older post of mine on army organization in the Norman Conquest. https://www.reddit.com/r/AskHistorians/comments/57cewr/how_did_william_the_bastardconqueror_raise_such_a/