There isn't enough evidence to confirm whether or not masturbation significantly affects immunity, but some preliminary research suggests that there may be some positive effects.
A small study from 2004 found that men had higher white blood cell counts after orgasm than after orgasm. White blood cells (also called leukocytes) are responsible for finding and attacking bacteria, viruses, parasites, etc. in the body. "These results show that components of the innate immune system are activated by sexual arousal and orgasm," said the researchers.
Tierney Lorenz, Ph.D., a clinical psychologist who studies sexual health and immunity, says masturbation is likely to affect immunity, although it may not mean what most people assume. "When people ask about immunity, they often talk about their susceptibility to disease, but the immune system actually does a lot of different things," she told mbg. "It helps your body recover from wounds, heal after exercising, and in the case of your period, it helps it tear off unused tissue and build it back up later."
When it comes to sexual activity, including masturbation, the part of the immune system that is primarily affected in women is related to reproduction. "The more someone deals with sexual activity and masturbation, the more they will send the message to their body that reproduction is a priority, and the more the immune system will act in a way that corresponds to this priority," explains Lorenz. In some ways, this will add to the person's net good as reproductive mechanisms can decrease reactivity to certain autoimmune problems, she adds.