Four rights groups had petitioned the courts to compel parliament to enact such a law before a general election on August 8.
The 2010 constitution requires that no more than two thirds of lawmakers should be men, a principle hailed at the time as a big step towards equality.
However the current male-dominated parliament has repeatedly rejected legislation to enforce this.
Four rights groups had petitioned the courts to compel parliament to enact such a law before a general election on August 8, saying there was a risk of a constitutional crisis.
High Court Judge John Mativo said that by failing to pass the required law, parliament was guilty of a "gross violation" of the constitution.
"Parliament has a constitutional obligation to enact the requisite legislation and failure to do so within the stipulated period is in my view unacceptable and a blatant breach of their constitutional duty," he said, according to a copy of the ruling seen by AFP.
He said that if parliament failed to enact the legislation within the stipulated time, "the petitioners or any other person shall be at liberty to petition the Honourable Chief Justice to advise the president to dissolve parliament."
The constitution gave parliament until August 2015 to enact the legislation, a deadline which was then extended by a year.
While Kenya's last election in 2013 landed more women than ever in parliament with 68 of 349 seats in the National Assembly, the country still lags behind much of the region in opening up politics to women.
World leader Rwanda has 61.3 percent of women in its lower house of parliament, followed by Ethiopia with 38 percent, Burundi with 36 percent and South Sudan with 28 percent, according to the Geneva-based International Parliamentary Union.
The improved showing of women in 2013 was largely due to another constitutional provision requiring that 47 "women representatives" be elected.
Kenyan analyst Nanjala Nyabola wrote recently that this had actually taken female politicians backward, as they were seen as only present to deal with women's issues rather than participating as "full parliamentarians".
Victor Kamau, lawyer for the Kenya National Commission for Human Rights which was one of the petitioners, hailed the ruling.
"The constitution... has been enforced, it has been brought alive in this judgement and we have been reminded as a people that this is the constitution we all aspired for," he told reporters after the hearing.