Sorry for the late reply. The answer is article 118 of the ANO:
"Power to prevent aircraft flying
118 (1) If it appears to the CAA or an authorised person that any aircraft is intended or likely to be flown:
(a) in such circumstances that any provision of article 3, 5, 6, 8, 20, 21, 35, 53, 59, 60 or 65(2) of this Order would be contravened in relation to the flight;
(b) in such circumstances that the flight would be in contravention of any other provision of this Order, of any regulations made thereunder or of JAR–145 and be a cause of danger to any person or property whether or not in the aircraft; or
(c) while in a condition unfit for the flight, whether or not the flight would otherwise be in contravention of any provision of this Order, of any regulations made thereunder or of JAR–145;
the CAA or that authorised person may direct the operator or the commander of the aircraft that he is not to permit the aircraft to make the particular flight or any other flight of such description as may be specified in the direction, until the direction has
been revoked by the CAA or by an authorised person, and the CAA or that authorised person may take such steps as are necessary to detain the aircraft.
(2) For the purposes of paragraph (1) the CAA or any authorised person may enter upon and inspect any aircraft. "
This is specifically allowed for under Article 16 of the Chicago Convention:
"Article 16
Search of aircraft
The appropriate authorities of each of the contracting States
shall have the right, without unreasonable delay, to search
aircraft of the other contracting States on landing or departure,
and to inspect the certificates and other documents prescribed
by this Convention."