Genesis 1:27 from the Bible states, "So God created mankind in his own image, in the image of God he created them; male AND female he created them."
It does not say either male or female. The keyword is "and".
In some ancient texts and apocryphal works from biblical times, there are stories of Adam and Eve that explain that they were created as spirits first, and then later, the Breath of Life" was breathed into them, making them "living souls," as stated in Genesis 2:7.
Since God possesses both male and female, generally interpreted as God the Father (male) and the Holy Spirit (female), spirits created in their image would be both. It was not until they were given living Earthly bodies that they were divided into sexes for reproductive purposes. (Angels in heaven do not marry.) Souls are indivisible; therefore, carry the characteristics of both masculine and feminine.
Because of Free Will, individuals express their natures according to individual preferences, not Divine dictate. If it were not so, Free Will would not exist. Everyone would behave exactly as proscribed. But it was intended that they behave according to their own nature, thus reflecting the Divine Spirit within them.
Think of it like a piece of fine art, or architecture, or literature. The work reflects the nature of the artist, designer, or author who is proud of their work. And as a Perfect Being, God cannot create junk or anything less than perfect, especially if it is "in His image".