Ruto's 1.5% levy on the salaries of all taxpaying Kenyans, to be matched by employers, was signed into law in June to fund an affordable housing program.
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.
Critics accused Ruto of going back on promises made during the August 2022 election campaign, when he declared himself the champion of impoverished Kenyans and pledged to improve their economic fortunes.
Ruto has defended the housing fund, saying it will construct homes for the poor, create employment and reduce public borrowing.
Kenya faces a host of challenges, including government revenue shortfalls and a plunging currency that has sent repayment costs on a public debt mountain soaring.
Treasury figures released at the end of June showed the East African nation had historically high debt of more than $66 billion, equivalent to around two-thirds of gross domestic product, GDP.
Kenya's Revenue Authority last month said it missed revenue targets for the June-September quarter by the equivalent of more than $500 million due to a depressed economy.
Inflation has also remained stubbornly high, at an annual rate of 6.9% in October.
The government has asked the court for a 45-day stay order on its ruling as it decides on the next course of action.