Why was each monkey wearing a cap on their head?

Because

They were imitating the seller
When he looked up the sky, he was very surprised to see monkeys sitting on the branches of a tree, each wearing a cap on his head. They had evidently done it to imitate him.
  Grammar articles: a/an, the