Volkswagen installed unlawful software to cheat emissions tests in thousands of cars that were sold in Britain, a High Court judge has ruled.