Pericarditis can be caused by a variety of factors, including viral infections, bacterial infections, fungal infections, or as a complication of a heart attack. Other causes include autoimmune diseases like lupus, rheumatoid arthritis, and trauma to the chest.