There isn't always logic behind each choice of prepositions. But "in" is used for enclosed things. The farm is thought of as the land, which things are on. The cows might be in the barn, but they are on the farm.
- For Teachers