The myth of Hayagriva- man with a horse neck (griva), is mentioned in Maitreyi Samhita ( 4.9.1). It explains why Lord Vishnu’s head had to be substituted with a horse head.
In the Vedas, Vishnu is the god of sacrifices and is identified as ‘yajna’. Once Agni, Indra, Vayu, and Yajna ( Vishnu) decided to perform a sacrifice. Gods decided that whoever receives a sacrificial gift first will divide it equally among the rest of them. Yajna (Vishnu) received the gift first. But he got greedy and refused to share it with others and ran away from the sacrificial grounds. The other gods immediately chased him. But Yajna who was quick-footed outran the gods and disappeared in the wilderness. After a while when he noticed that gods were nowhere in sight, Yajna was tired and decided to take a quick nap. But he did not want to take any chances as gods would catch him anytime, so he planted one end of his arched bow on the ground rested his head on the other end, in readiness to shoot an arrow, and dozed off.
Meanwhile, the gods after searching high and low finally found Yajna ( Vishnu) fast asleep with his head rested on his bow. They decided to cut his head off. But who would do the task? They commanded the ants in the wilderness to come together and gnaw at the bowstring of Yagna’s bow. But the ants refused to oblige and the Gods made a deal that ants would from then on get a part of sacrificial oblation in the form of clarified butter (ghee). Tempted by the offer ants agreed and quickly gnawed off the string. Released from the tension of the bowstring the arched bow snapped and flung the head of Yajna/ Vishnu high into the air decapitating him. The head rose into the sky and turned into a bright golden ball of fire and became the Sun. The Gods then replaced the head of Vishnu with a horse head, and thus Hayagriva was born.