LDS doctrine is clear that we existed as spirits with God prior to entering mortality on Earth. But it's a little less clear on how (or if) we existed prior to that. Most Mormons have a vague belief in 'Personal Eternalism', the idea that we existed in some way as "intelligences" prior to being "born" as spirits. However, some Mormons, notably Bruce R. McConkie, reject this view, and interpret "intelligence" or "light of truth" as some kind of spiritual matter radiating from God that gets organized into a spirit body at "spirit birth".
The fundamental theological divide between these two views is not critical to this discussion, but is worth mentioning for context. If we always existed as intelligences, we are necessary beings, and we exist independent of even God, who in classical theology is the only necessary being. Most Mormons don't have a problem with this. For those who do -- Bruce R. McConkie --, however, the only way to make God the only necessary being is to deny our eternal nature altogether, whereby we become contingent beings. We began to exist when "born" as spirts, per McConkie.D&C 93 wrote:29 Man was also in the beginning with God. Intelligence, or the light of truth, was not created or made, neither indeed can be.
30 All truth is independent in that sphere in which God has placed it, to act for itself, as all intelligence also; otherwise there is no existence.
Personal Eternalism goes way back. A great source for how the various perspectives arose is Blake Ostler's dialogue article, The idea of pre-existence in the development of Mormon thought. Roberts and Widstoe were heavy promoters of this way of thinking. As Ostler explains, there are many Mormon philosophers (as such) through present-day who vouch for the idea, such as McMurrin and Madsen. For our friends over at LDS Freedom Forum, the preeminent scholar of the Constitution, W. Cleon Skousen has a detailed political theory of the entire universe based on Widstoe's thesis.
There are many in-between positions. For instance, it's popular to believe that there are entire classes of intelligences out there that "advance" per their personal ambition until they qualify to be born as spirits. Everything essential to your mental life is there within the intelligence, but many intelligences are fulfilling other spheres of creation, not the sphere of humanity.
Widstoe wrote: the primeval personality possessed, from 'the beginning,' the distinguishing characteristics of every intelligent, conscious, thinking being - an independent and individual will
For Skousen (Widstoe?), intelligence fills all matter, and when God commands it, it freely obeys, and that's the source of God's power over the material world.from Skousen's view wrote:Intelligences” are self-aware entities that are self-existent and at various levels of complexity and progression. They are independent and act voluntarily, and cannot be compelled
That's enough background information to ask the vexing question, does every intelligence have a gender? If gender is eternal, then it must be the case that every intelligence at every degree of "complexity" and step of "progression" has gender. Fine you say, that's what you want as a fundamentalist Mormon, but consider the implications of that. It may be the case that every rock is filled with male and female intelligences, but certainly, these intelligence performing functions outside of the human or animal spheres of creation don't have stomachs or toes or sex organs. And so the doctrine of "eternal gender" essentially decouples gender from biology, just like every liberal psychiatrist has been trying to tell you. Sure, you can say that there would never be a mistake in matching male intelligence to a certain kind of physical body, but biological hardware becomes and accidental property of gender in a certain sphere, gender is something that has this entire other life for innumerable primeval personalities not existing within a world based on biological sex.
If you go the McConkie route, then gender isn't eternal because YOU are not eternal. Maybe that's good enough, as long as the spirit child is born with sex organs. But what determined gender in that case? God, presumably, by fiat. That doesn't usually work for Mormons, who believe God will cease to be God if not following external law. But suppose we're willing to say it comes down to God's word. He said Sunday is holy, so it's holy; he said this person has certain organs and therefore male. But we can entertain the counterfactual that if Wednesday were proclaimed as the Sabbath then Wednesday would be holy, and that's not an evil thought. Then neither is it wrong to think that any individual could have been created the opposite sex and that would have been okay. God could, in fact, at any time, change someone from a man to a woman if it were to his will and pleasure to do so. Many might be okay with the fact that he hasn't done that and so that's good enough, but the reason why many wish gender to be eternal, is to avoid that even as a possibility. By fiat = arbitrary.