A Kenyan court ruled on Tuesday that a controversial housing levy introduced by President William Ruto was illegal, dealing a blow to his plans to shore up depleted government coffers.

The 1.5-percent levy on the salaries of all taxpaying Kenyans, to be matched by employers, was signed into law in June to fund an affordable housing programme.

A three-judge panel at the High Court in Nairobi said the introduction of the tax lacked a comprehensive legal framework and the exclusion of informal workers was "discriminatory and irrational".

"An order is granted prohibiting the respondents from collecting... the charge known as the affordable housing act," said judge David Majanja.

The levy was imposed as part of a finance law that raised taxes on a wide range of items in a move that has had a ripple effect in a country already hamstrung by high inflation.

Anger over the rising prices, particularly for basics such as food and fuel, led to a series of sometimes deadly protests against Ruto's government earlier this year.

East Africa's economic powerhouse is facing a host of challenges, including depleted government revenue and a plunging currency that has sent repayment costs on a public debt mountain soaring.

The government has asked the court for a stay order on its ruling.