Yali,a part of the Hindu temple architecture - What purpose does it serve?

Madurai Meenakshi temple Yali in pillars in a mandab  en.wikipedia.org
As far as Hindu temples are concerned, especially the old temples, you can seldom run into a temple that does not have  weird, fiery-looking  mythical creatures nicely carved on stone pillars. They are often called ''Yali'', (also known as Vyala or Vidala in Sanskrit). A Yali may be depicted as  part lion, part elephant and part horse, and in similar shapes. Sometimes, it could be  a leogryph (part lion and part griffin) with some bird-like features.

Believed to be more powerful than
the lion, the tiger or the elephant,  depiction of Yali in south Indian sculpture has been around for several centuries and their presence increases the curiosity of the visitors to the temples. In the north it has been there the since the Gupta period.

The  iconography and image of the Yali may be quite striking and impressive and one can see variations in its depiction. It has a cat-like graceful body, but the head of a lion with tusks of an elephant (gaja) and tail of a serpent. At some places,  it is shown standing on  the back of  Makara, another mythical creature ( vehicle or mount of Budha (Mercury).  To make it more impressive, some images of Yalis  have  three-dimensional representations.
Yali statues ; Kailasanatha temple.Kamchipuram,
alamy.com
What is the reason behind the presence of  these unearthly and mysterious Images or icons in the Hindu temples? What purpose do they serve ? These vexed questions need to be answered and many of us have no acceptable answer. One logical reason that we have come closer is according to the Hindu tradition,
Thanjavur big temple, Dvarabalas. Shunya
these graceful creatures are believed to
protect and guard the temples and ways leading to the temple. This is the reason why you can find them in the entrance halls (mandabam) of the temples. Of course, at the entrance to the main interior shrine - garbagriha or Srikovil, on either side, you can see the sentinels called Dvarabalas having popping eyes, wielding a mace or Gatha. Yalis come in different forms and shapes They often possess the body of a lion and the head of some other beast, most often an elephant (gaja-vyala). Other may: lion-headed (simha-vyala), horse-(ashva-vyala), human-(nir-vyala) and the dog-headed (shvana-vyala) ones
Yali pillars at Krishna temple at Hampi, Karnatakaen.wikipedia.org
Yali, Madurai temple, TN n.wikipedia.org
According to Vaishnava tradition, Yali is a  fusion of  elephant, lion and snake. It has the head and body of a lion but with an  elephant trunk and has the tail of a serpent. The effects of Yali in the hall of temple are three-fold, it has the strength of an elephant, ferocity and speed of a lion and most importantly it instills fear as a serpent. 

The other reason is the image of Yali will ward off evil forces, implying that it will remove of all  negative forces around us.
Sharabh to subdue Narashimha quora.com
Perhaps in some  Vishnu temple procession during  major festivals one can see lord Narashimha (Vishnu) riding on the Yali Vahana. During the avatar of Narashimha (half human and half lion)  to kill the demon king Hiranyakasyab to save his bakta Prahladha, Narashimha became too ferocious to be subdued after killing the demon. Upon Devas' appeal  Shiva finally created  Sharabh, as fearful as Narasimha but with wings and sharp claws. In the ensuing battle Narashimha could not win Sharabh and finally Lord Shiva appeared before him and told him he had sent Sharabh only to subdue him. Finally Narashimha turned into Vishnu and Sharabh into Shiva.
Church of Scotland, Scotland. Paisley Abbey pload.wikimedia.org/
For many, Yali or Vyalas or Shardulas represent a genre called grotesque in art forms often found in old European and other buildings and such similar depictions are found all over the world. They are similar to gargoyle in European architecture or leogryph in Asian architecture. It is
Gargoyles of Siena Cathedral, Italy en.wikipedia.org
carved or formed grotesque with a spout designed to convey water from a roof top and away from the side of a building. It is quite common among old Italian buildings. But unlike them, a Vyala is usually carved on a bracket supporting a cornice (a cornice is a decorative molding).

Yali Gupta periodQuora
Yali Gupta period.Quora
Yali Gupta period..quora.com
 Above images: Yali at Gupta temples  Later, the lion represented Gupta empire or the imperial signature!!  Yali is seen in many Gupta temples  in Nachna, Bhumra, Udaygiri, Chandrawati and  many others in MP, Rajasthan etc. The symbol lion has been around in many forms in Gupta architecture, in  the past 2000 years; the Gupta and even succeeding non-Gupta kings(Vaishnav) used Yali in their religious buildings......................................
Chandikesvara Temple in Hampi (Vijayanagara empire.Lumen Learning
Above image: Pillars at Chandikesvara Temple in Hampil Pillars of Vijayanagar temples are often engraved with images of yali, or hippogriffs. Vijayanagar era architecture is broadly classified into religious, courtly, and civic architecture.  Its  style is a nice fusion of the Chalukya, Hoysala, Pandya, and Chola designs. Presence of yali is part of Vijanagara temple architecture.
Yali stone pillars in atemple. S.India.Pinterest
It is said depiction of Yalis is as per the Shastras. Yali (From Vyala meaning vicious in Sanskrit) is a popular temple motif along with Apasaras, Yakshas, Kshetrapala, etc. But unlike them, a Vyala is usually carved on a bracket supporting a cornice Mostly they face the passage, a sign of protecting the temple and the Gods in the temple.
Madurai Azhagar Kovil, Yali Pillars in the hall (mantab) tripadvisor.in
Yali, it is true, may nicely fit into the pantheon of hybrid animals in Hindu mythology.  We can take the weird and grotesque stone images as the pinnacle of human imagination, but the ability to give expression to such a strange concept  in stones is something that makes all the difference. This kind of art form in hard stone is a difficult task that requires amazing skill and dexterity. 

 https://www.quora.com/What-does-Yali-found-in-the-pillars-of-many-South-Indian-temples-symbolize-Are-they-just-mythological-creatures
 https://en.wikipedia.org/wiki/Yali_(mythology)