The study of the pathology of the immune system, including the underlying mechanisms of immune-related diseases.