It's one of those paradoxes of life. In order to answer this question, we have to know how tetanus the bacteria works inside our body (and how the vaccine prevents it).
Tetanus is caused by the bacterium Clostridium tetani. Spores of it are found all over the place, especially in the soil. We usually associate tetanus with rusty nails mainly because it's easy to puncture yourself with a nail and a rusty one is most likely to have all sorts of germs on it. But rust is nothing special... its not necessary for the bacteria's survival.
Once inside the body, the bacteria start to multiply and establish an infection. C. tetani produces two exotoxins, tetanolysin and tetanospasmin. We don't really know what tetanolysin does, but tetanospasmin is a neurotoxin and is super lethal. Once inside you, it travels through your blood vessels and lymphatics, where it gains access to certain parts of the nervous system: peripheral nerve terminals (nerve endings found all over the body), the spinal cord, and the brain. The toxin is absorbed by the nerve axon and transported across synaptic junctions until it reaches the central nervous system, where it attaches to gangliosides (certain proteins that serve in cell signaling) at the ends of inhibitory motor nerve endings. Here, the toxin cleaves other proteins that are involved in nerve signaling, and thus prevents any electrical movement between synapses.
Once you have no communication between motor neurons, this causes problems for the muscles that they attach to. Remember that tetanus affects inhibitory neurons, so if one neuron cannot inhibit the next motor neuron, that motor neuron will continue sending signals to a muscle fiber, putting it in a state of permanent contraction, which causes muscle rigidity and spasms. This is why tetanus is called "lockjaw".
So now you know how tetanus is caused. What does the vaccine do?
The tetanus vaccine is a toxoid. Toxoid vaccines are made by treating the toxins with heat or chemicals such as formalin. Doing this alters the toxin slightly, destroying the ability of the toxin to cause illness (in this case, to bind to the components of the nervous system) but it doesn't alter the toxin too much--the immune system will still produce antibodies against it and these antibodies can also bind to the potent unaltered form of the toxin. Once the toxin molecule (the antigen) is bound by antibodies, it can be destroyed a number of ways by cells of the immune system. Over a period of time, we get tetanus boosters so that we can increase the proliferation of the memory B and T lymphocytes that are responsive to the neurospasmin antigen, which is basically like refreshing our immune system's "memory".
Just FYI, there is another tetanus shot you can get which, technically speaking, is not a vaccine. It is tetanus immunoglobulin, and is essentially the serum from someone else who has antibodies against tetanus. Injecting yourself with this will give you temporary immunity in case you might have just been infected. This is called passive immunization because unlike active immunization (what is described above) the body doesn't produce its own antibodies.
Now, you know how the vaccine (and vaccines in general) work. So, now we can ask:
What happens if you get a tetanus shot with a rusty needle? (Assuming that: you have no prior immunity to tetanus and you are receiving the tetanus vaccine, not the immunoglobulins)
Essentially, we are asking: what happens if you get hit with the tetanoplasmin producing bacteria and the the weakened form of the tetanoplasmin toxin at the same time? The short answer is: you will still get sick.
This is because when you administer a vaccine, you need to give your immune system enough time to develop the antibodies via B lymphocytes, the cells that make the antibodies. B and T lymphocytes are part of your body's adaptive immune system, which typically kicks in 6-7 days after the innate immune system (which acts immediately upon invasion by pathogens). By the time a B cell recognizes the antigen, replicates, and creates antibodies to the weakened form of the tetanoplasmin, the bacteria from the rusty needle could have proliferated and produced enough toxin to cause damage.
So there you have it. Don't get a shot with a rusty needle, even if it's a tetanus shot :)
Thanks for reading