A US federal court has ruled that the Trump administration has no legal right to freeze billions of dollars in grant funding to Harvard.