The activity of milking a farm animal on Shabbat was assumed to be forbidden, but the Gemara searches for the source for that prohibition.
The Gemara relates: Rav Naḥman bar Gurya happened to come to Neharde’a. The students asked him:
For what prohibited labor is one who milks liable? He said to them: For milking.
For what prohibited labor is one who sets milk to curdle liable? He said to them: For setting milk to curdle.
For what is a person who makes cheese liable? He said to them: For making cheese.
They said to him: Your teacher was a reed cutter in a swamp who did not know how to explain the Mishna to his students.He came and asked those questions in the study hall. They said to him:
One who milks is liable for performing the prohibited labor of extracting, which is a subcategory of threshing, on Shabbat. This is because when one extracts milk from a cow it is similar to the act of threshing, where one removes the desired content from its covering.
One who sets milk is liable for the prohibited labor of selecting because part of the milk is separated and made into congealed milk.
One who makes cheese is liable for building because the cheese within the milk assumes a solid form, which is similar to the process of building.
Regarding the action of milking, even though extracting is not itself a primary category of labor, the Gemara explains the prohibition of milking in terms of extracting. It does not say that one who milks is liable due to threshing because they are completely different. In contrast, milking and extracting are similar (Adderet Eliyahu). Many commentaries found the categorization of milking under the rubric of the primary category of threshing difficult, as most authorities hold that the prohibition of threshing applies only to plants (see Tosafot). Some explained that milking is prohibited by Torah law according to Rabbi Yehuda. However, the halakha is that it is prohibited only by rabbinic decree (Rashba). Others explained that the extracting mentioned with regard to milking on Shabbat is a subcategory of smoothing, not threshing (Rabbeinu Tam in Sefer HaYashar). Yet other commentaries ruled that since, in certain respects, an animal is considered an item that grows in the ground, milking indeed falls under the rubric of threshing (Ge’onim, Sefer HaHashlama).
Farm animals that must be milked on Shabbat present a challenge in the modern world that religious kibbutzim have dealt with in a variety of different ways.