They did not, at least not in Europe or China. The roles of insects in pollination was discovered only in the 18th century, and it took until the late 19th/early 20th century for the impact of bees in agriculture to be appreciated and used.
In both early Europe and China, the importance of insects in pollination was unknown. In the west, bees show up in literature quite early, and the female/male parts of plants are known to some degree. Theophatrastus (387-287 BC) ran an experiment in shaking the flower bloom of male dates over female, notices dust, and concludes the male aids the female in the production of fruit. A vague notion of male and femalness in plants, as well as sex of some sort would linger, but the details of both plant reproduction and pollination would have to wait.
There is a similar story in China. Bees were less commonly talked about in early texts, possibly due to the diminished importance of honey because China had sugar cane (from ~3000bc, introduced from Polynesia). None the less, bees are briefly mentioned in the earliest fully extant agricultural text (Qiminyaoshu, "Essential Techniques for the Welfare of the People") in the Six Dynasties, and slowly increase. By Yuand and early Ming sources talked about individual farmers going all in on exclusively apiculture, and maintaining hundreds of hives. Similarly, a vague notion of male and female plants existed. In Qiminyaosu there is a detailed discussion of male and female hemp plants and instructions on how to select them to maximize hemp output. However, there are doubts as to just how deep that understanding was: it is possible it is a vague "male/female" mapping to human sex similar to Europe. Regardless, this notion would persist as well.
Neither Europe or China would discover the importance of insects pollination, or that in agriculture until much later.
The discovery of the importance of pollination would have to wait until the scientific revolution. Starting around 1675, a century of experimentation was required, starting with pinning down exactly what each part of flowers did, and ending with Joseph Gottlieb Kölreuter running half a decade of experiments. The earliest experiments revolved around removing parts of flowers such as the anthers (which produce pollen) and stigmas (which receive it), and seeing if seeds were formed. These initial experiments, ran over a variety of plants such castor oil plants, would reveal how plants produce and receive pollen. It would take awhile to be widely accepted-a decade after they were performed the French botanist Tournefort thought that the stigma excreted unwanted sap as pollen.
The initial hints that it insects were important came from experiments by Philip Miller on tulips, where he removed the stamens (the part of the flower, consisting of anthers and a filament supporting them). The made sure there was no dust (that is, pollen) in the air, but noticed bees with dust on their bodies and legs was able to "impregnate" the flower, and concluded insects could carry pollen. Further later experiments showed pollen could be potentially carried in the air as well. But it was the details of Kölreuter's experiments that popularized it. Starting in 1761, over a period of five years, he ran extraordinarily detailed experiments, to the point of counting the number of grains of pollen produced, and seeing exactly how many were necessary to fertilize various flowers. He figured out flower nectar was the what bees used to make honey, described in detail stamens and stigmas of flowers, that some stamens ripen before stigmas, and concluded that insects where the main source of pollination for many plants.
There would still be much to learn-the next century would see further advancements and refinements of these mechanisms, such as wind pollinators producing more pollen, or the role of pollination in cross breeding, genetics and evolution. By the late 19th century the impact of bees on agriculture was starting to become clear, and with the development of infrastructure, roads, and trucks in the early 20th century the modern practices around transporting beehives developed for agriculture developed. Even in the last half century, we are still learning: integrating modern genetics, cytology, and ecology have allowed us to understand details of this process far better than before. This importance in agriculture was only really quantified in studies starting after 1950, then in the 60s extended to a huge variety of crops.
It took slightly longer for this to reach China, with pollination ecology starting in the 1970s. As opposed to large monoculture farms with hives specifically for pollination, at this time and even to this day to some extent China remains small holder based farms surrounded by strips of forests, native habitats or flowers, with wild or semi-domesticated bees. The field and understanding of bees in agriculture has rapidly progressed from there, especially in the last 20 years.
Sources:
Natural history and science:
"The Natural History of Pollination" by Procter, Yeo, and Lack
Impacts on agriculture:
"Pollination ecology in China from 1977 to 2017" by Zongxin and Ren
"Combing the Landscape: An Economic History of Migratory Beekeeping in the United States" by Rucker and Thurman
On China:
"Science and Civilization in China Volume 6: Biology and Biological Technology: Part IV: Traditional Botany: and Ethnobotanical Approach" by Georges Metailie.
"Pre-modern Beekeeping in China: A Short History" by Pattinson