The UK does not need to pay Rwanda after it pulled a deal between the two countries, a court has ruled.