The federal police have been ordered to return the majority of the thousands of documents seized during a raid on the CFMEU's Canberra headquarters in August.
The decision is another embarrassing setback for police investigating Canberra union officials, after prosecutors were forced to drop blackmail charges, due to lack of evidence, against organiser John Lomax earlier this year.
Justice Richard Refshauge, in a decision handed down in the ACT Supreme Court on Wednesday, found part of the search of the Dickson offices had been unlawful.
Justice Refshauge ruled that police withheld information from the magistrate in order to get the warrant.
"I have found the seizure under the second warrant to be invalid because of the failure to disclose fully the circumstances that were required to be disclosed for the issuing officer, the learned magistrate, to make a proper decision about whether to issue a warrant that is able to be executed after 9pm," the decision said.
"In the light of the strict duty of full disclosure, it seems to me that this failure meant that the warrant was issued on a false basis and is therefore invalid."
The judge ordered information seized – which the union says was electronic data – under the second warrant should be destroyed or returned to the union with seven days.
But the police have been allowed to keep information taken before the second warrant was issued at 9pm.
Although the admissibility of that information could be subject to challenge if it were used in future court proceedings after Justice Refshauge made declarations of non-compliance for a number of police obligations, including obligation to copy and return seized information as soon as practicable and not providing a copy of the first warrant upon arrival.
The judge also ordered the AFP pay the CFMEU's legal costs for the legal challenge against the raid.
The AFP had already voluntarily delayed part of its investigation into the ACT branch of the union by not using documents seized during the search until after the court challenge could be decided.
An estimated 20 police attached to the royal commission into trade unions swarmed the Dickson headquarters in August in search of evidence of blackmail and corruption.
Police are believed to have taken thousands of electronic and hard copy files, as well as mobile phones, while frisk-searching union officials and staff, removing posters, and going through the office safe and ceiling cavity.
They stayed at the headquarters for about 13 hours.
The original search warrant expired at 9pm, and police were forced to obtain a second warrant, which was then executed.
The union alleged, during a three-day hearing in October, that the confiscation of documentation from the headquarters was unlawful on a number of grounds, including that its members were restricted from observing police, that there was no evidence to support the issuing of a second warrant, and that copies of the seized material were not given to CFMEU officials as required.
He ruled that a copy of the warrant was not made available to the occupier or a representative of the premises as soon as reasonably practicable, and the occupier was improperly and unduly impeded in the exercise of the entitlement to observe the search.
Outside court, CFMEU ACT branch secretary Dean Hall lauded a "fantastic result for union, workers, and civil liberties".
Mr Hall said the CFMEU valued the work police did for the community, but the authorities also had to act within the law.
"The Australian Federal Police officers attached to the trade union royal commission taskforce have clearly broken the law," Mr Hall said.
"In breaking the law, they didn't follow their own procedures or the procedures set down by the courts.
"[Justice Refshauge] has found they did not follow those procedures and made findings against them."
Mr Hall said the CFMEU had always and would continue to co-operate with lawful orders to produce documents.
"This is solely about people overstepping, and unfortunately it's about the good name of the federal police being dragged through the mud in a politicised way by the Liberal government in attack on unions and workers in this country."
"It is distressing that money paid to us as costs could be money used to tackle domestic violence, the scourge of ice in the community, and several other important community initiatives.
"Unfortunately, that money was used to attack workers and their union, but the union has to recuperate that money so it can be used for the benefit of our members."