Why does vaccination provide long-lasting protection against a disease, while gamma globulin (IgG) provides only short-term protection?
Because vaccination involves active immunity.
I just copied this from an answer from a thread with the same question.
Now before we proceed, let us define some terms first.
Let us define the term antigen first. The antigen is like an organism's ID. It needs to be presented before it is recognized. The analogy here is a demon(foreign organism) went to heaven(human body) and in the gate, an ID(antigen) was required. Because the people in the gate saw that the demon had a Hell ID, the Generals(Lymphocytes) were informed what this demon looked like and commanded their subordinates(antibodies) to apprehend the demon.
There are two kinds of immunity:
1. Active Immunity
It is very important to remember that when a foreign immunogenic(capable of inducing immune response) antigen is found in the body, our body, specifically our B lymphocytes, produces substances called antibodies to make it easier for our white blood cells to get rid of the offending organism.
B Lymphocytes, upon antigen recognition, will differentiate into Plasma cells and Memory B cells. Plasma cells secrete the antibody specific to the antigen, and Memory B Cells, as the name implies, will remember that foreign antigen to react quicker in future encounters of the organism with the same antigen, and hence, gives a Long term but slow acting protection.
Example: Vaccination- a part of the organism is injected to the individual therefore stimulating antibody production without causing the disease.
2. Passive Immunity
Passive immunity is administering the antibody itself. And therefore, no memory B cells were produced. However, because the antibodies are readily available, the antigen is neutralized quickly, without the help of B lymphocytes. However, it is only short term because Memory B cells are not produced. Hence, it gives a short term but rapidly acting protection..
Example: Rabies Immunoglobulin is injected to individuals bitten by animals to counter the virus' effects in the body. By the time the body produces antibodies against the rabies virus, the person may already be dead.
Hope this helped! :)