There are several factors at work here, and I don't think the relative importance has been determined with any certainty. In descending order of my own estimation of their importance, vaccine-induced immunity:
- Stimulates the systemic immune system, rather than the mucosal,
- Presents only antigens that will inactivate the virus when bound by
antibody,
- and does not disrupt the immune system, which can result in a better response.
From a 2005 review on the mucosal immune system:
The mucous membranes covering the aerodigestive and the urogenital tracts as well as the eye conjunctiva, the inner ear and the ducts of all exocrine glands are endowed with powerful mechanical and chemical cleansing mechanisms that degrade and repel most foreign matter. In addition, a large and highly specialized innate and adaptive mucosal immune system protects these surfaces, and thereby also the body interior, against potential insults from the environment. In a healthy human adult, this local immune system contributes almost 80% of all immunocytes. These cells are accumulated in, or in transit between, various mucosa-associated lymphoid tissues (MALT), which together form the largest mammalian lymphoid organ system1.
The mucosal immune system has three main functions: (i) to protect the mucous membranes against colonization and invasion by potentially dangerous microbes that may be encountered, (ii) to prevent uptake of undegraded antigens including foreign proteins derived from ingested food, airborne matter and commensal microorganisms, and (iii) to prevent the development of potentially harmful immune responses to these antigens if they do reach the body interior. At variance with the systemic immune apparatus, which functions in a normally sterile milieu and often responds vigorously to invaders, the MALT guards organs that are replete with foreign matter. It follows that upon encountering this plethora of antigenic stimuli, the MALT must economically select appropriate effector mechanisms and regulate their intensity to avoid bystander tissue damage and immunological exhaustion.
So, by injecting a vaccine, it's expected we can provoke a more robust response than a natural infection that stays in the lungs. A few COVID cases result in high viremia (virus in the blood), but I don't know of any studies comparing viremia to duration of IgG levels, etc.
Regarding antigens; viruses have evolved ways to trick the immune system, e.g., presenting an antigen that is attractive to the immune system, but the virus can still function when it is bound by antibodies. In COVID, this is the post-fusion state of the spike protein itself. The mRNA vaccines, at least, include mutations that block the spike from transitioning to the post-fusion state.
And finally, successful viruses actively interfere with immune function. COVID has been found to induce immunodeficiency in recovered patients. This prevents the immune response to a natural infection from being as strong as you would expect, even though it is a more severe challenge to the immune system than a vaccination.