They are illegal, but the DfT or even the transport minister can issue permission for a defined trial/test/event.
For example, vehicle racing of any kind is illegal on our roads, but twice there's been permission for restricted routes to be closed for Tour de France stages here. Another...