It would make Germany the first European country to offer intersex people the choice of identifying as neither male nor female.
The case was brought by a registered female whose chromosome test confirmed they were neither one sex nor the other.
Activists described it as a "small revolution".
The constitutional court in Karlsruhe has given the government until the end of 2018 to pass a law specifying a category other than male or female.
It said current regulations on civil status were discriminatory against intersex people.