It is a mystical legend. Locals believe that Gibraltar will remain British territory as long as there are Barbary Macaques in Gibraltar.
A popular belief holds that as long as Gibraltar Barbary macaques exist on Gibraltar, the territory will remain under British rule. In 1942 (during World War II), after the population dwindled to just a handful of individuals (just seven monkeys), British Prime Minister Winston Churchill ordered their numbers be replenished immediately from forest fragments in both Morocco and Algeria because of this traditional belief.
Local military believe this so much that they have someone who's job it is just to feed the macaques.
Gibraltar's Barbary macaque population was under the care of the British Army and later the Gibraltar Regiment from 1915 to 1991, who carefully controlled a population that initially consisted of a single troop. The 'Keeper of the Apes' would keep the official records, maintaining an up-to-date register for each ape, listing their births and names and supervising their diet, which they drew officially every week. The food allowance of fruit, vegetables and nuts was included in the budget, set by the War Office at £4 a month in 1944. They would humorously announce births in the 'Gibraltar Chronicle':— "Rock Apes. Births: To Phyllis, wife of Tony, at the Upper Rock, on 30th June 1942— a child. Both doing well." much to the delight of readers. They were named after governors, brigadiers and high-ranking officers. Any ill or injured monkey needing surgery or any other form of medical attention was taken to Royal Naval Hospital Gibraltar and received the same treatment as would an enlisted service man. When UK-based infantry units were withdrawn and garrison duty was left to the Gibraltar Regiment, the Government of Gibraltar took over responsibility for the monkeys