Here is the
Acquisition and Disclosure of Communications Data Code of Practice document.
2.1. The acquisition of communications data under RIPA will be a justifiable interference with an individual’s human rights under Articles 8 and, in certain circumstances, 10 of the European Convention on Human Rights only if the conduct being authorised or required to take place is both necessary and proportionate and in accordance with law.
2.2. RIPA stipulates that conduct to be authorised or required must be necessary for one or more of the purposes set out in section 22(2) of RIPA:15
• in the interests of national security;16
• for the purpose of preventing or detecting crime17 or of preventing disorder;
• in the interests of the economic well‑being of the United Kingdom so far as those interests are also relevant to the interests of national security;18
• in the interests of public safety; 19
• for the purpose of protecting public health;20
• for the purpose of assessing or collecting any tax, duty, levy or other imposition, contribution or charge payable to a government department;
• for the purpose, in an emergency, of preventing death or injury or any damage to a person’s physical or mental health, or of mitigating any injury or damage to a person’s physical or mental health;21
• to assist investigations into alleged miscarriages of justice;22
• for the purpose of assisting in identifying any person who has died otherwise than as a result of crime or who is unable to identify himself because of a physical or mental condition, other than one resulting from crime (such as a natural disaster or an accident);23
• in relation a person who has died or is unable to identify himself, for the purpose of obtaining information about the next of kin or other connected persons of such a person or about the reason for their death or condition;24 and
• for the purpose of exercising functions relating to the regulation of financial services and markets or to financial stability.
Out of this list, the only one that could potentially apply is the 'detecting crime' one.
The document notes for that bit state:
"Detecting crime includes establishing by whom, for what purpose, by what means and generally in what circumstances any crime was committed, the gathering of evidence for use in any legal proceedings and the apprehension of the person (or persons) by whom any crime was committed. See section 81(5) of RIPA. Where an investigation relates to an allegation of criminal conduct by a member of a public authority, that public authority (or another public authority appointed to investigate the complaint) may use their powers under Chapter II to obtain communications data for the purpose of preventing or detecting the alleged or suspected crime where the investigating officer intends the matter to be subject of a prosecution within a criminal court. Should it be determined there are insufficient grounds to continue the investigation or insufficient evidence to initiate a prosecution within a criminal court, it will, with immediate effect, no longer be appropriate to obtain communications data under RIPA. "