I had this because of a fungal infection when I moved to a tropical climate. The humidity caused a fungal infection on my scalp. I went to a doctor complaining of scalp itching and dandruff. I didn't even know about the pus until the doctor pointed it out to me.
Thankfully, the treatment was easy. I just had to use an anti-fungal shampoo for a week. The infection went away and never returned.