The government has to prove that a person's conduct has direct negative impact on the military. If the acts are consensual, but it causes social problems later that's enough to get the person in trouble
All extramarital is still illegal, consensual included.