Billions of dollars meant for barracks, schools and training programs have been shifted to fund the Pentagon’s expanding role in immigration enforcement.