A federal district judge ruled Monday that the Defense Department could not compel members of the armed forces to be vaccinated against anthrax without their consent.