The immune system detects viral infections through various mechanisms, including the recognition of viral antigens by immune cells. This triggers an immune response aimed at eliminating the virus. However, an excessive or dysregulated immune response can contribute to disease severity, as seen in conditions like cytokine storm.