The origin of Sri Panchamukhs Hanuman can be traced to a story in Ramayana.
During the war between Lord Rama and Ravana.
Ravana took help of Mahiravanka who is the king of pathala.
Lord Hanuman in order to protect Lord Ram and Lakshman formed a fortress with his tail.
Mahiravana took the form of Vibeeshana and took Lord Ram and Lakshman to pathala loka.
Hanuman entered pathala loka in search of Rama and Lakshmana, He
found out that to kill Mahiravana he had to extinguish five lamps
burning in five different directions at the same time, so he has
taken the Panchamukha form with Hanuman, Hayagriva, Narasimha,
Garuda and Varaha faces and extinguished the lamps and killed Mahiravana.
According to Hanumath Prakaranam in Sri Vidyarnavatantram, Anjaneya
has five faces (Pancha Mukha) and ten weapons. The five faces are
that of Lord Hanuman, Lord Narasimha, Lord Adivaraha, Lord Hayagriva, and Lord Garuda.