Bee, or other insect stings/bites, will cause a reaction to occur due to chemicals being released from your immune system. This can result in anywhere from a small bump to anaphylaxis, which can be life-threatening if not treated right away.
From Southern Cross Medical Library:
An anaphylactic reaction occurs when the body's antibodies respond to the insect venom by releasing chemicals such as histamine and serotonin that trigger the allergic reaction.
Whatever the reaction, it is correct to say that the reaction to an insect sting/bite is a defense mechanism of the body. An interesting study done by Stanford University School of Medicine was done and discusses these immune mechanisms:
Innate immune responses occur in subjects exposed to a foreign substance, such as a pathogen or a toxic material like venom, for the first time. [...] Immune cells called mast cells, which reside in most of the body’s tissues, are poised to unleash signals that turn on defense responses when a pathogen or toxin intrudes. Prior immunization is not required for these types of innate immune responses, nor is the development of specific antibodies. In contrast, during an adaptive immune response, the immune system creates antibodies that can recognize the toxin or pathogen that is invading the animal’s system. Adaptive immunity is typically a faster, more specified and more effective form of defense than innate immunity, the research team explained.
More explanation of the non-specific immune response:
If a bee stings you, the presence of the bee venom triggers a nonspecific immune response. White blood cells arrive first on the scene to rid the body of bee venom antigens. As war wages between antigens and white blood cells, battle signs may appear on the affected skin. Inflammation (redness, swelling, heat, and pain) results as the body wards off invaders.
If the body detects an antigen that it previously met, a specific immune response occurs. In this response, the body has been trained to recognize and neutralize a familiar specific antigen; its immune system "remembers" the antigen. Such systemic (not restricted to the initial infection site) immunity enables a faster, longer lasting immune response than does a nonspecific response.
Therefore, these reactions to bee stings and other foreign toxins help us to better develop our immune system to protect against potential future encounters with these insects.