This seems like the Faded Sun Trilogy, by C. J. Cherryh.
There are numerous references in the book to the sex being decided by age.
There came another touch at degh’s body, faint, tremulous. It was Nagn, an older youngling. And it tore back with a shriek of dismay.
“Honored,” it cried, “I burn!”
It had happened: next eldest had gone prematurely into Change. Suth cried out with relief and shut degh’s eyes.
The pain moved lower. Muscle contractions began at last, fever increasing, skin sloughing and peeling. The younglings brought food, and bathed degh, and applied unguents to the swollen parts.
Scarcely supported by the younglings the Honored Nagn moved again to degh’s side, touched, shuddering in degh’s own pain.
The choice was Suth’s. Suth’s body was making it. The swelling continued as one vestigial set of organs was absorbed, and the other began, in convulsive heaves of Suth’s body, to press down into the membrane covering the aperture . . . descended, evident as it would never be henceforth save in mating.
“Male!” a youngling declared.
It's set on a desert planet and from what I can see browsing the book it appears to be what you're looking for.