Both "They have a headache" and "They have headaches" are grammatically correct ways to describe the situation where two people are experiencing headaches simultaneously.
The choice between them depends on the emphasis and context of the situation:
"They have a headache": This emphasizes the shared experience of a singular headache. It suggests that both individuals are experiencing the same type or intensity of headache.
"They have headaches": This emphasizes that each individual is experiencing their own separate headache. It implies that the headaches may vary in type or intensity between the two people.
Both options effectively convey the idea that multiple people are experiencing headaches, so the choice between them ultimately depends on the specific nuance you wish to convey.