Via Shayana Khadidal, this excellent post by Jack of Kent, who appears to be a British attorney, regarding the detention at Heathrow airport of David Miranda. The gist:
What section 40(1)(b) says:
So schedule 7 provides a limited power to question and a limited power to detain.
Both the powers to question and to detain are conditional on the purpose of whether a person falls within section 40(1)(b) of the 2000 Act.
So the next question is fundamental – what does section 40(1)(b) say?
Section 40(1)(b) is a definition clause, and it provides the following definition of “terrorist”:
a person who…is or has been concerned in the commission, preparation or instigation of acts of terrorism.
Section 40(1)(b) thereby is a limiting definition – the questioning (and any period of detention) under schedule 7 is for seeing if a person falls within this definition. Accordingly, any questioning (and any period of detention) which is not for this specified purpose is outside the scope of the provision. [Emphasis supplied.]
Jack of Kent continues with regard to the search and confiscation of Miranda's property:
This limit is also significant as we look at the power of search and examine: paragraph 9 limits the power to examine property to determine whether the person falls within section 40(1)(b). It is not a general power of search.
However, once property has been taken, then paragraph 11(2) provides it can be retained:
(a) the purpose of examination, for a period not exceeding seven days beginning with the day on which the detention commences, [or]
(b) while [the officer] believes that it may be needed for use as evidence in criminal proceedings [...]
So, once the property has been taken from the detained person it can be kept for evidence in criminal proceedings, regardless of whether the detained person is within the category of “terrorist”.
Thus while the search was illegal, the UK can, under this law, keep the confiscated material if "it may be needed for use as evidence in criminal proceedings." But Miranda was not arrested. So what criminal proceedings?
Read the whole thing. It lays out clearly why the UK detention of Miranda was unlawful.