The question is not whether it would be politically possible to make such a law, but whther such a law in the hypothetical it passed, would survive constitutional scrutiny.
The answer, not totally clear.
I think it is clear that it would be declared unconstitutional. In my opinion, such a law would not even survive the "rational basis" test of ordinary Equal Protection Clause cases. But the Court has made it clear that a higher level of scrutiny is appropriate where "fundamental rights" like voting are concerned. "We have long been mindful that, when fundamental rights and liberties are asserted under the Equal Protection Clause, classifications which might invade or restrain them must be closely scrutinized and carefully confined." Harper v Virginia Board of Elections (1966)
http://caselaw.findlaw.com/us-supreme-court/383/663.html And remember that here we are talking about depriving millions of people of their voting rights, and in a way without precedent--for there has *never* been any blanket prohibition of soldier voting, though the reluctance to allow absentee voting has at times discouraged it. Indeed, the Court has specifically used the Equal Protection Clause to protect soldiers' right to vote, as in Carrington v. Rash, 380 U.S. 89 (1965):
"It is argued that this absolute denial of the vote to servicemen like the petitioner fulfills two purposes. First, the State says it has a legitimate interest in immunizing its elections from the concentrated balloting of military personnel, whose collective voice may overwhelm a small local civilian community. Secondly, the State says it has a valid interest in protecting the franchise from infiltration by transients, and it can reasonably assume that those servicemen who fall within the constitutional exclusion will be within the State for only a short period of time.
"The theory underlying the State's first contention is that the Texas constitutional provision is necessary to prevent the danger of a "takeover" of the civilian community resulting from concentrated voting by large numbers of military personnel in bases placed near Texas towns and cities. A base commander, Texas suggests, who opposes local police administration or teaching policies in local schools might influence his men to vote in conformity with his predilections. Local bond issues may fail, and property taxes stagnate at low levels because military personnel are unwilling to invest in the future of the area. We stress -- and this a theme to be reiterated -- that Texas has the right to require that all military personnel enrolled to vote be
bona fide residents of the community. But if they are in fact residents, with the intention of making Texas their home indefinitely, they, as all other qualified residents, have a right to an equal opportunity for political representation. "Fencing out" from the franchise a sector of the population because of the way they may vote is constitutionally impermissible. "[T]he exercise of rights so vital to the maintenance of democratic institutions,"
Schneider v. New Jersey, 308 U. S. 147, cannot constitutionally be obliterated because of a fear of the political views of a particular group of
bona fide residents. Yet that is what Texas claims to have done here..
"We deal here with matters close to the core of our constitutional system. "The right . . . to choose,"
United States v. Classic, 313 U. S. 299,
313 U. S. 314, that this Court has been so zealous to protect means, at the least, that States may not casually deprive a class of individuals of the vote because of some remote administrative benefit to the State.
Oyama v. California, 332 U. S. 633. By forbidding a soldier ever to controvert the presumption of nonresidence, the Texas Constitution imposes an invidious discrimination in violation of the Fourteenth Amendment."
https://supreme.justia.com/cases/federal/us/380/89/case.html
Once again, what justification could be given for depriving members of the military of their right to vote, under either "rational basis" or heightened scrutiny? The initial post said to maintain civilian control of the military, but this misinterprets what civilian control means. It means that soldiers must obey orders of their Commander-in-Chief, the president, not that they have no say in determining who is elected. Once can argue that allowing certain speeches by soldiers, even if permissible for civilians, could have adverse effects on military morale or discipline. But how is a solider casting a secret ballot having any effect on morale or discipline?
Once again, remember that the Court in Carrington v. Rash not only saw soldier voting as normal, but condemned attempts to abridge it (whether from fear of how soldiers will vote or from other motivations) in the same kind of language it used to condemn abridgement of civilian voting rights.