If the second and third men were wearing blue hats, the first would have to be wearing a red hat. But the first man answered that he didn't know which colour hat he was wearing. So the second and third men can't both have been wearing blue hats.

If the third man was wearing a blue hat, the second man would have to be wearing a red hat, since they can't both be wearing a blue hat. But the second man answered that he didn't know which colour hat he was wearing. So the third man can't have been wearing a blue hat.

Therefore, the third man was wearing a red hat.