That's the flower's way of assuring that its pollen gets attached to an insect for transfer to another flower. The bees don't like being slapped in the face, so they usually find some other kind of plant to get nectar. Some of the bees learn to chew a hole in the side of the flower and get to the nectar through this side door. When they do that, pollination does not occur because the pollen on the bee does not reach the top of the stigma. So it seems that the only reason a bee visits a flower is to get what it wants and not to perform a pollination service.
Pollination occurs as a happy accident for the flower.
Many other kinds of insects, such as wasps, flies, beetles, thrips and other kinds of bees that feed on nectar or pollen also pollinate flowers by accident. However there are at least some insects that intentionally see to it that the flowers they visit get pollinated. The way a yucca flower is built, it cannot be pollinated in the ordinary way, and it depends on the special service of a yucca moth to do it. When the moth comes to a yucca flower it gathers up a ball of pollen, and then goes to the ovary of the female part of the flower where it lays some eggs. It then climbs to the top of the female part of the flower and places the ball of pollen on the stigma where it needs to be for pollination to occur.