bees, barn cats, working dogs, and milk animals all have what’s called a symbiotic relationship. This is a mutually beneficial arrangement that’s common all over the animal kingdom - there are birds that eat the fleas off of big mammals, fish that eat dead scales and skin off of other fish, and wolves and corvids that work together to find food.
In the case of barn cats - humans provide the cats with shelter and a food source, and the cats, eating the mice, prevent said mice from eating our food. Same thing with dairy animals - we provide them shelter and food, they give us food. Bees are the same exact thing. This is like, middle school biology guys