Poland, Hungary and the Czech Republic broke EU law by rejecting refugees, the top EU court says.