Hayagriva is the horse head of incarnation of Bhagvan
Vishnu. There is a popular belief in Hinduism that nothing in the universe
happens without a reason. Hayagriva incarnation was a necessary to keep the
Dharma in the universe intact. But for Vishnu to have the head of a horse there
should be a reason and it was provided by a curse of Goddess Lakshmi.
Legend has it that once Bhagvan Vishnu looked at the face of
Goddess Lakshmi and laughed. Goddess was taken aback by this unruly behavior.
She was distraught and she thought her Lord had seen something ugly on her
perfect face.
Goddess Lakshmi, who was unable to find the real reason,
thought that her Lord had another woman in his life or he would not laugh at
her like that.
Goddess Lakshmi was soon possessed by wrath and in anger she
cursed his head to fall off. She believed the life of a widow to be better than
her husband taking another woman was his wife.
This curse was put to use to annihilate the horse-headed
demon who had got the boon that only a horse-headed being will kill him.
The head of Vishnu was chopped by his bowstring, when Devas
tried to awaken him from his deep sleep.
You can read the story of Hayagriva incarnation here.