Campaigners defeat government over legal aid cuts for prisoners