The court ultimately ruled that the government had a legitimate reason to believe that David Miranda was involved with people who were at the time acting or threatening to act in a manner which was designed to influence a government and forward a political agenda, and those acts had the potential to cause death or serious property damage. All those appear true on their face, and thus the law states the detainment was legal.
That is a real stretch, you do know how ridiculous that sounds? First lets be clear: "involved with people" means The Guardian Newpaper and its journalists working on the story. Secondly you could use the same argument to start raiding and shutting down any media outlet you felt like and start detaining anyone the journalists ever related with - family and all. Real Gestapo tactics.
Every media outlet acts in a manner that could be interpreted as designed to influence a government. It could be argued that any newspaper/journalist is forwarding some political agenda. And the most ridiculous claim by Lord "Justice" Laws: "if [some leaked data that we can imagine might possibly be in the medias hands] was published, it [might for example] reveal personal details of members of the armed forces or security and intelligence agencies, thereby endangering their lives.". Neither Lord "Justice" Laws nor the security apparatus knows (by their own admission) what or how much data was leaked by Snowden, nor has any such data that "reveals personal details of members of the armed forces or security and intelligence agencies" been leaked or published by The Guardian or anyone else publishing Snowden material.
Lord "Justice" Laws might have just as easily said with the same straight face: "We do not know what data they have, but if they happen to have plans for top secrete weapons, and publish it, then they will endanger everyones lives.". So basically what the high court has done is make up a possible threat in order to get the ruling they wanted (or were told to get more likely).
No, what Lord "Justice" Laws really did was cover for unaccountable entities operating in the dark with little to no oversight, Exposing their illegal activities and a call for oversight and transparency is a fundamental obligation of any free independent press concerned with the wellbeing of society. This ruling only hints at how desperate they want to be able to raid Media outlets that start exposing their wrongdoing through responsible whistleblowing. We are already way down that slippery slope it seems, so I guess that it is only a matter of time now...