A consultation over plans to reform a key disability benefits test was unlawful, the High Court has ruled.