Vaccines work by essentially teaching your immune system to recognize a pathogen. If your immune system is in a very weakened state, it likely will not 'learn', and even if it does, it may not be in any condition to fight the infection, even if it recognizes it as such. Of course, things are much more complicated, but in people with severe immuno-deficiency (such as advanced AIDS or people who are actively taking immune suppressants) a vaccine will not have any effect (some kinds of vaccines even risk infecting that person with the disease, though I beleiev this is not the case with any of the Covid19 vaccines).