The most obvious reason why a vaccine may have limited use is mutation. Flu vaccinations are only useful for a season since the dominance of the many Influenza serotypes changes pretty quickly over time, and new serotypes are routinely spun off through mutation.
The other likely reasons for needing boosters is differences in average immunological memory length vs. the aggressiveness or stealthiness of a pathogen. It's not fully understood why, in a general sense, these differences occur and how they interact. Immune systems and pathogens exist as a complex ecosystem, so it could very well be the case that there is no general answer to the question of why immunity only lasts so long for a given pathogen. We can study a pathogen as an independent thing though, and get an informed "lifespan" for a particular vaccine based on risk of reinfection over time and the consequences of reinfection. Risk of reinfection can be found by studying the number and types of adaptive immune system components active against a specific antigen over time in a vaccinated population. Often the data for how long a vaccination lasts also comes from epidemiological study. Essentially, watching to see when vaccinated people start getting infections again.
With hepatitis B we have a lot of direct antibody measurements to work with. One vaccination generates enough memory B cells targeting HBsAg to give immunity for around ten years, which is the average lifespan for those cells. After that, HBsAg targeting helper T cells still exist and can spur the "rapid" production of antibodies over 25 years after vaccination. The extremely long term helper T driven immunity takes longer to actively fight a new infection, but it's fast enough to outpace hepatitis B before any significant damage is done.
Currently in use inactive virus rabies vaccines create memory B cells, but the creation is delayed and not very strong. Multiple inoculations of the inactive virus generate an increasingly stronger production of memory cells until enough exist to last for their lifetime, which is around ten years. This happens because memory B cells can create more memory B cells of the same type after being activated and differentiating into a plasma cell. Through a few iterations of this, weak initial memory B production can be magnified greatly. This is one reason why boosters often give longer term immunity than the initial vaccination. However even with the strong memory B production, these vaccines don't generate sufficient memory in the longest term systems to guarantee an effective response over multiple decades. It does seem possible to create a vaccine against rabies which could be single dose and last decades though. There's nothing special about the rabies virus which makes this impossible, but one factor does complicate the creation of a new vaccine. With little exception, symptomatic rabies is fatal. It's a vaccine where 90% is just not good enough. If you're going to say your single dose rabies vaccine lasts 10+ years, it better work for that long practically every time.
Another thing to consider is pathogens which are naturally pains to immunize against for one reason or another. The icon for this is HIV, which does a table flip on the adaptive immune system by infecting and killing T cells directly, as well as becoming latent in these very long living cells if they live long enough after infection to go dormant again. So even if you fight off the infection with a very strong immune response, even with help from medication, eventually any T cells carrying HIV DNA will activate and produce viruses again. You never become immune to HIV through the adaptive immune system, so traditional vaccines against the virus which rely on teaching this system just aren't effective. This is but one example. There's a big world of life out there with all kinds of surprising competitive behavior.
Useful references
Hepatitis B immunity:
https://pubmed.ncbi.nlm.nih.gov/17298912/
https://pubmed.ncbi.nlm.nih.gov/16171909/
Rabies immunity:
https://www.ncbi.nlm.nih.gov/pmc/articles/PMC3486289/
HIV latent behavior:
https://www.ncbi.nlm.nih.gov/pmc/articles/PMC3234450/
General immunological memory information:
https://www.ncbi.nlm.nih.gov/books/NBK2383/
https://www.ncbi.nlm.nih.gov/books/NBK27158/
https://www.ncbi.nlm.nih.gov/pmc/articles/PMC3253344/