This question already has an answer here:
Contemporary Hindus believe that cows are the most sacred animals and should not be eaten. There are even groups in North India that kill people who eat cows.
However, many of the Dharma Shastras, such as the Apastamba Dharma Sutras, say you can kill cows in Vedic sacrifices and eat them:
- [But the meat] of milch-cows and oxen may be eaten.
- The Vājasaneyaka declares ‘bull’s flesh is fit for offerings.’
The cow isn't even in the list of "forbidden creatures to eat" list:
- Eating the meat of forbidden [creatures],
- for example:— a dog, a human, village cocks or pigs or carnivorous animals
However, verse 29 does say this:
- [Nor can one eat the meat] of one-hoofed animals, of camels, of the Gayal [wild cow], of village pigs, of Sarabhas, and of cattle.
But it is immediately followed by verse 30 listed above, which says "but milch cows and oxen may be eaten".
Then, later on there is a verse that says this:
- [The same penance as for killing a Shudra must be performed], if a milch-cow or a full-grown ox [has been slain] without a reason.
The commentator, Haradatta, says that a reason for hurting a cow is due to anger or for meat:
‘A reason’ for hurting a cow is, according to Haradatta, anger, or for meat.
So this probably means you can eat the breeds of bovine that are limited to milch (dairy) cows, oxen, and bulls, but not other breeds of cattle (such as the Gayal).
So, having said all this, where did the notion that cows are sacred come from?