Immune function is modulated by caloric balance via leptin, so dieting causes immune suppression (and this is primarily a result of glucose metabolism, so keto diets are the worst, in this regard). In addition, dieting increases cortisol, which is immunosuppressive.
Refeeds, glutamine, and anti-oxidants, particular Vit C, can help avoid illness while dieting.