Only when they do so in a very public way (e.g. publishing books, appearing on radio/TV talk shows, etc.), or are actively trying to convince fellow members to change their beliefs and oppose LDS Church teaching (e.g. organizing private religious study groups involving other Church members).
The notion that a President Romney would need to worry about being excommunicated for pursuing legislative or military agendas that the Church leadership didn’t agree with is simply ludicrous. The LDS Church leadership is very pragmatic, and wouldn’t dream of spoiling the PR dream of having a Church member as President of the United States. The leadership would be more likely to issue a bland statement about the “Church doesn’t take on official position on matter X”, if public attention were drawn to an apparent conflict between Church teaching and Romney’s actions as President.
Which is extremely sad....because IMO, the mormon church is more focused on symbolism than substance.