They can’t join the military if they are illegal....many would, of course, if it would make them legal...that is one part of the “Dream Act”.
Because I am pretty sure that a non-citizen living in another country can already get US citizenship by serving in the US armed forces.