Media regulator had called for 13 radio and TV stations to suspend their news editors, producers and heads of programming over their coverage of the latest detention of the popular rapper and politician.
Two activists petitioned the court on behalf of the Uganda Journalists Association (UJA) to have the order struck down.
The media clampdown has provoked allegations of censorship of criticism of the government.
Uganda's high court on Thursday blocked a government bid to suspend dozens of top journalists, on the grounds their coverage of the arrest of popstar MP Bobi Wine had endangered national security.
The Uganda Communication Commission (UCC) earlier this month called for 13 radio and TV stations to suspend their news editors, producers and heads of programming over their coverage of the latest detention of the popular rapper and politician.
Two activists petitioned the court on behalf of the Uganda Journalists Association (UJA) to have the order struck down.
"I am aware of the national security interests, however regulatory actions cannot be used to trample the rights of people's freedoms and right to information," judge Lydia Mugambe Ssali told a packed courtroom in Kampala.
"The application is allowed and injunction ordered against the respondent (the UCC)."
The ruling was hailed by journalists present in court.
"This is a historical ruling that has shaped the rights and principles of our profession," the UJA's head of media safety and human rights Arnold Anthony Mukose told AFP.
"We have been trampled upon by illegal, oppressive and irrational directives not only from UCC but other state agencies. In this case the judiciary has stood with us," he added.
UCC lawyer Abdu Salaam Waisswa said: "We are going to analyse the ruling and see the way forward."
Alarm
The UCC order prompted diplomats from the EU, US and another 14 countries to raise alarm about Uganda's clampdown on media freedom and protests.
Wine, whose real name is Robert Kyagulanyi, was detained for allegedly staging an illegal protest in 2018—charges fellow opposition MPs have decried as ridiculous—and later freed on bail.
The popular singer is the figurehead of a new generation who grew up under President Yoweri Museveni but want to see change.
He has emerged as a real challenger to the veteran president who intends to run for a sixth term in 2021.
Ugandan authorities have frustrated Wine's efforts to hold concerts at his private club, and have detained him repeatedly for procedural misdemeanours.
His detention prompted protests in Kampala that were broken up by police with tear gas and rubber bullets.
Wine is also facing treason charges along with more than 30 opposition politicians over the alleged stoning of Museveni's convoy after a campaign rally in the north-western town of Arua in 2018.