It usually occurs when bacteria or fungi enter the brain tissue after an infection or severe head injury.