(Read the problem here)
D and C can not see anyone, so it’s impossible for them to have any clue.
A can see B and C. Seeing B and C’s hat, A still not getting the answer, so A can not say anything.
B only can see C. But if B has the same colour as C, A must have know the answer and shout it already, but A don’t.
With this fact, B knows that A can’t know the answer only by seeing B and C, means B and C have different colour. Seeing C’s hat is red, B can conclude that B’s had is blue. So B can give the answer.