The ruling is a win for the US justice department, which is probing Mr Trump over classified documents.