Sexual dimorphism in immune function is a common pattern in vertebrates and also in a number of invertebrates. Most often, females are more 'immunocompetent' than males. The underlying causes are explained by either the role of immunosuppressive substances, such as testosterone, or by fundamental differences in male and female life histories. Here, we investigate some of the main predictions of the immunocompetence handicap hypothesis (ICHH) in a comparative framework using mammals. We focus specifically on the prediction that measures of sexual competition across species explain the observed patterns of variation in sex-specific immunocompetence within species. Our results are not consistent with the ICHH, but we do find that female mammals tend to have higher white blood cell counts (WBC), with some further associations between cell counts and longevity in females. We also document positive covariance between sexual dimorphism in immunity, as measured by a subset of WBC, and dimorphism in the duration of effective breeding. This is consistent with the application of 'Bateman's principle' to immunity, with females maximizing fitness by lengthening lifespan through greater investment in immune defences. Moreover, we present a meta-analysis of insect immunity, as the lack of testosterone in insects provides a means to investigate Bateman's principle for immunity independently of the ICHH. Here, we also find a systematic female bias in the expression of one of the two components of insect immune function that we investigated (phenoloxidase). From these analyses, we conclude that the mechanistic explanations of the ICHH lack empirical support. Instead, fitness-related differences between the sexes are potentially sufficient to explain many natural patterns in immunocompetence.