The municipality of Buitrago del Lozoya (1,952 inhabitants in 2014;
2,650 ha; unofficial website) is located in the north of the Community of Madrid, 75 km of Madrid.

Buitrago del Lozoya, established on a promontory inscribed in a
meander of river Lozoya, is the only town in the Community of Madrid
to have fully preserved its medieval fortifications, proclaimed in
1931 a National Historical Monument, the alcazar (fortified town)
included. The town is surrounded by a wall of 800 m in perimeter,
including both Moorish and Christian elements. The part of the wall
dominating the river is of more than 6 m in height and 2 m in width,
lacking towers; the other part of the wall, more prone to attack, has
a minimal height of 9 m and a width of 3.2 m, and is protected by
several towers. The main entrance of the town was defended by the
clock tower, a pentagonal tower of some 16 m in height, erected in the
14th century.
The alcazar, built in the 13th-15th century in Mujédar style on the
remains of an earlier Moorish citadel, is nearly square, protected by
seven towers. In the 15th century, Íñigo López de Mendoza (1388-1458, 1st Marquis of Santillana and Count of Manzanares) built a palace inside the citadel, which was visited by Kings John II and Philip III, by Juana la Beltraneja and her mother Juana, and by the Dukes of the Infantado. Destroyed by a blaze in 1536, the palace was subsequently rebuilt; burned down again in the 17th century, the palace was suppressed, its site being transformed in the 1930s into a bull ring.
Buitrago was the capital of the Community of the Town and Land of
Buitrago, chartered in 1096 by King Alfonso VI.

The Town Hall, built in the 1940s, houses the Picasso Museum,
inaugurated in 1985. Born in Buitrago in 1909, Eugenio Arias Herranz
exiled after the Civil War to Vallauris (France), where he was the barber of Pablo Picasso and one of his closest friendsuntil the painter's death. In 1983, Arias refused to sell the works Picasso had offered him and donated them to the Provincial Council of Madrid.
[The Independent, 2 May 2008]

The flag and arms of Buitrago del Lozoya are prescribed by a Decree
adopted on 20 September 2001 by the Government of the Community of
Madrid and published on 24 January 2002 in the official gazette of the
Community of Madrid, No. 20, p. 8 (text) and on 19 March 2002 in the Spanish official gazette, No. 2678, p. 11,290 (text).
The symbols were originally adopted in April 1988 by the Municipal
Council. The Heraldry Assessors and the Royal Academy of History
recommended minor modifications on 26 May 1988 and 10 June 1988,
respectively. Other Heraldry Assessors proposed modifications on 16
April and 30 May 1991, but the Municipal Council did not follow up. A
new proposal, taking into account the aforementioned recommendations,
was eventually adopted on 30 April 2000.
The symbols are described as follows:

Flag: In proportions 2:3, quartered per saltire, 1. and 4. Vert a red bend fimbriated yellow, 2. and 3. Yellow with the words "AVE MARÍA" sable. In the center is placed the municipal coat of arms.Coat of arms: Or a holly oak vert on a base of the same the trunk
superimposed with an oxen sable. The shield surmounted by a Royal
Spanish crown.

Diego Hurtado de Mendoza y Figueroa (1415/1417-1479), the elder son of
Íñigo López de Mendoza, First Marquis of Santillana, was made Duke of the Infantado (full title, "Duque de las Cinco Villas del Estado del Infantado") in 1475; subsequently, the Dukes of the Infantado were made first-rank Grandees of Spain, and were therefore allowed to wear
their hat in the presence of the king. Íñigo de Arteaga y Martín (b. 1941) is the 19th Duke of the Infantado.
"Vert a bend gules fimbriated or" are the oldest known arms of
Mendoza; subsequently modified several times, the arms always included
a red bend on a green field. The arms quartered per saltire were
introduced by the first Marquis of Santillana and appear on a seal
dated 1440; the marquis quartered his father's arms (Mendoza) with his
mother's arms (de la Vega). His descendants were known as Mendoza de
Guadalajara or Mendoza de l'Ave María. In the representations of these
arms, the first quarter is inscribed with "AVE MARÍA" while the third
quarter is inscribed with "PLENA GRATIA" (or, at least "GRATIA").
[José Luis García de Paz (UAM), Los poderosos Mendoza website]

The arms featuring the bull and the holly oak were granted in 1096 by
Alfonso VI, when establishing the Community of the Town and Land of
Buitrago.
The flags in actual use (photo, photos, photo) appear to lack the "AVE MARÍA" writing in the yellow quarters.