The historic origin of the flags is related to the distinctive signs with military purposes. Cloths when kings and noblemen who went to the war, used to draw the figures of their coat of arms to identify their armies. They decorated them with their colours, so that the fighters could see them during the confusing course of the battle.
The flag, raised in the military camps, was also a sign that helped the forces distribution, and the flag hoist in castles and ships, meant that the master was in that place. However, the most important thing was not the flag but the coat of arms that could be seen in the elevated cloth. In Spain, and contrary to what had been the German peoples -the Visigoths-, introduced the roman's custom: the tradition to decorate the shields with colours or symbolic figures. This high medieval tradition, with the passing of the time, gave way to the appearance of coats of arms during the XI and XII century.
According to the legend, the king Pelayo ordered to draw a lion in his shield as an acknowledgement for killing one, when he was prisoner in Cordoba, after the Guadalete battle. The lion's heraldry figure passed to his descendants that were the Kings of Oviedo, and it passed then, to the Kings of León. A little bit less romantic are other historic explanations that attribute the lion's origin to the own's León kingdom, whose name developed from the latin word "Legio" (due to the Legio VII Gemina that had there the camp) to the word "Leo".
Also the castle has its own chronicle: the count Fernán González was the one who ordered to draw a castle in his shield, as a way to expressing that he had conquered Castilla when the king of León made his count title hereditary.
Junta de Castilla y León