The UK will not have to pay Rwanda millions of pounds over a failed migrant deportation deal after winning an international court case.