A judge on Tuesday struck down a Montana law that defined ''sex'' in state law as only male or female, finding that it was unconstitutional.