In ancient India, oxen and bulls were sacrificed to the gods and their meat was eaten. But even then the slaughter of milk-producing cows was prohibited. Verses of the Rigveda refer to the cow as Devi (a powerful goddess), identified with Aditi (mother of the gods) herself.
Even when meat-eating was permitted, the ancient Vedic scriptures encouraged vegetarianism. One scripture says, "There is no sin in eating meat... but abstention brings great rewards."
Later, in the spiritually fertile period that produced Jainism and Buddhism, Hindus stopped eating beef. This was mostly like for practical reasons as well as spiritual. It was expensive to slaughter an animal for religious rituals or for a guest, and the cow provided an abundance of important products, including milk, browned butter for lamps, and fuel from dried dung.
Some scholars believe the tradition came to Hinduism through the influence of strictly vegetarian Jainism. But the cow continued to be especially revered and protected among the animals of India.
By the early centuries AD, the cow was designated as the appropriate gift to the brahmans (high-caste priests) and it was soon said that to kill a cow is equal to killing a brahman. The importance of the pastoral element in the Krishna stories, particularly from the 10th century onward, further reinforced the sanctity of the cow.