One person's freedom fighter may be another's terrorist, but David Miranda is very clearly neither. Yet he was detained at Heathrow airport for nine hours under schedule 7 of the Terrorism Act 2000. That the high court has now found his detention to be lawful is disappointing, to say the least.

If someone travelling as part of journalistic work can be lawfully detained like this – questioned for hours without a lawyer present, his electronic equipment confiscated and cloned and all without the merest suspicion of wrongdoing required – then clearly something has gone wrong with the law.

We've been here before. Schedule 7 suffers the same glaring flaws as the old section 44 counter-terrorism power that also allowed stop and search without suspicion. Such laws leave themselves wide open to discriminatory misuse: section 44 never once led to a terrorism conviction but was used to stop people like journalist Pennie Quinton. In a significant victory, Liberty took her case to the European court of human rights and the power was declared unlawful.

So it's surprising to see our judges go the other way on Miranda's detention, especially given the circumstances. He was on his way home from a meeting in connection to his partner Glen Greenwald's work on the Snowden revelations when stopped. There was certainly something particularly chilling to press freedom at work here. Liberty and other organisations intervened in his case on just this point, arguing that the detention violated article 10 of the European convention, the right to freedom of expression.

Our riled security services' transparent intimidation and interference with Miranda is shocking. But it's also important that we use his case to shed light on the murky everyday reality of schedule 7. The power is consistently used to target minorities – you're 42 times more likely to be stopped if you're Asian than if you are white – and there's a sense within these communities that such stops are now an expected part of travel. The people I represent have appalling stories of their delays and invasive questioning about their religious beliefs and attendance at mosques. Imagine having to schedule that into your airport experience as a matter of course.

There's a case pending at the European court of human rights – again taken by Liberty, which has been shouting about this for years – of a British Asian man also detained at Heathrow. He was kept for four and a half hours, questioned about his salary, his voting habits, the trip he'd been on and more. The police copied all his documents and credit cards and kept his mobile phone for eight days. This is the dark underbelly of our terrorism legislation at work – innocent people treated with a contemptible lack of respect for no reason other than the colour of their skin.

Yesterday's Miranda judgment has worrying implications for press freedom, race relations and basic justice. We always hope our judiciary will be the restraining hand on this kind of state conduct, but too often the very mention of national security also has a chilling effect on the courts. Here the suggestion is that disclosure of the Snowden material would assist terrorists and therefore endanger lives. How do you challenge such an opaque assertion? It is the state's "get out of jail" card when their agents have abused their powers. I do a lot of terrorist work in the courts and those involved in such activity have no illusions about the extent of surveillance. They operate on the assumption that everything is tracked; it is just that they are prepared to take risks. The central contention here was that the use of this power interfered with freedom of the press, a liberty that is fundamental to a free society.

It is also important to recognise that our judiciary is currently on the back foot. It is not only the European court of human rights that is being attacked by the tabloids and Tea Party tendency; many of our own judges have been at the receiving end of vitriol for being too committed to human rights. We are now seeing our judiciary in defensive mode. This judgment is another setback but it will form part of a continuing conversation between our courts and the European court of human rights on this issue and many others. As this goes on, let's keep the core message clear: schedule 7 may be lawful, but it is really rotten law.

Helena Kennedy QC is a Labour peer