A few years ago, Beatriz Madriz enlisted in the Marine Corps. Then, just before heading to boot camp, a recruiter told her that she had to divorce her husband if she still wanted to join the Marines—because he was an illegal immigrant.

"They told me they would even pay for the divorce," said the 22-year-old Portland, Ore., resident. "I wasn't going to do that."

Amid...