The 2000 Terrorism Act, which I helped introduce, was not passed with people like David Miranda in mind. The issue then was how to secure lasting peace in Northern Ireland, and the act was designed to make it difficult for Irish dissident terrorists to come to the mainland. Schedule 7 of the act, which has come to public attention this week following Miranda's detention at Heathrow, was retained from earlier legislation on the advice of Lord Lloyd of Berwick. Reviewing the evidence, he had found that the ability of officers to randomly stop and search people who were entering or leaving the country had disrupted terrorist operations.

So it was right in 2000 – and it is still right today – that police or immigration authorities should have powers to detain and question people in order to determine whether they are terrorists.

However, it is also right that schedule 7 powers can only be used "for the purpose of determining" whether the detained person is a terrorist. The use of the power to detain and question someone who the examining officer knows is not a terrorist is plainly not for this purpose, so it would neither be within the spirit nor the letter of the law.

There is no suggestion that Miranda is a terrorist, or that his detention and questioning at Heathrow was for any other reason than his involvement in his partner Glenn Greenwald's reporting of the Edward Snowden story. The state has not even hinted there is a justification beyond that involvement. While there may be relevant facts of which I know nothing, it is reasonable to proceed on the basis that was the reason for the powers being used.

The Terrorism Act defines a terrorist as someone "involved in committing preparing or instigating acts of terrorism". Miranda is plainly not committing or preparing acts of terrorism. Instigate is defined by the Oxford Dictionary as to "bring about or initiate an action or to incite someone to do something". Publication in the Guardian is not instigating terrorism. If it is obvious to the state the person detained is not a terrorist, the state must have some purpose other than determining whether he is a terrorist in using the power – and that would render the use of the power unlawful.

The state may wish that journalists would not publish sensitive material, but it is up to journalists, not the state, to decide where to draw the line. If the state contends a person holds information unlawfully there are a range of powers it can use to restrain its use, though they are all subject to legal limitations. The schedule 7 power is not given to restrain the use of information.

The home secretary, Theresa May, said on Tuesday: "I think that it's absolutely right that if the police believe that somebody is in possession of highly sensitive stolen information that could help terrorists, that could risk lives or lead to a potential loss of life, that the police are able to act, and that's what the law enables them to do." I have no idea whether there was a proper basis for the beliefs to which May refers, but even if one assumes there was, such beliefs do not justify the use of the schedule 7 power.

Miranda's supposed possession of the Snowden material (I don't know if he did have possesion of it) was in connection with assisting Greenwald. The examining officer must have known that. Of course, there may be cases where a terrorist masquerades as a journalist, but that is clearly not so in this case.

It is important to understand the ramifications of May's justification. She is not suggesting there is an issue about whether Miranda is a terrorist – the only lawful basis on which his detention and questioning could be justified. Rather, she is suggesting that he was in possession of stolen material which could help terrorism, presumably by publication. There is a world of difference between the two.

Had schedule 7 been in force when Salman Rushdie was writing Satanic Verses, May's justification would have allowed his detention and questioning and the removal of his manuscript.

Schedule 7 does not contain a power to detain and question journalists simply because the state thinks they should not be able to publish material because of the damage publication might do, or because they do not approve of where the information came from. The state has exceeded its powers in this case. The sooner the courts make this clear, the better.