I got this all from a comment on the internet after asking myself this question
For ruminant animals, like cows, they can produce B12 through bacteria in the rumen, but they need cobalt in their diet to do so. Since lots of soil is depleted with cobalt, these cows need a cobalt supplement. Most cattle are not grass-fed, but grain-fed, so their cobalt-supplemented feed may not provide them a significant amount of B12, in which case they need a B12 supplement.
All ruminants (including sheep, cattle and goats) require cobalt in their diet for the synthesis of vitamin B12. Vitamin B12 is essential for energy metabolism and the production of red blood cells. Cobalt deficiency in soils can cause vitamin B12 deficiency in livestock.
Cobalt concentrations in feeds are not well known and therefore cattle diets are supplemented with cobalt at approximately 0.1 ppm to ensure adequate production of vitamin B12...Ruminal production of vitamin B12 is lowest, and production of B12 analogs is highest, on grain-based diets (as compared to forage-based diets).
Note that pigs and chickens are not ruminants, so they get B12 from their diet. Since their feed consists of grains, soy, and other plant foods (which are currently not a significant source of B12 due to modern agriculture), they need supplementation.
Synthesis of this vitamin in the alimentary tract is of considerable importance for animals. Swine requirements vary from 5 to 20 µg per kg of feed, with young pigs and breeding animals having the highest requirement. Early on, Anderson and Hogan suggested inclusion of orally administered vitamin B12 at the rate of 0.26 µg daily per kg of live weight
Poultry species requirements vary from 3 to 10 µg per kg of feed. Squires and Naber supplemented a corn-soybean diet for laying hens at control (no supplementation) or one, two or four times the NRC requirement for vitamin B12. Egg production was reduced after 12 weeks on the diets when hens were fed the two lowest vitamin B12 intakes. As vitamin B12 intake increased, shell thickness decreased and egg weight, hen weight, and hatchability increased.
Evidence that we can get B12 from the bacteria on the roots of plants, but not when they're grown in sterile conditions: