Dr. McCoy, as the Branch Admiral of Starfleet Medical, is most likely the Surgeon General of Starfleet. He's the man responsible for the whole of Starfleet's medical personnel, and as such, has the right to inspect, in person or by proxy, any and/or all medical staff and facilities in Starfleet.
Likewise, the Fleet or Sector Medical Admiral could do so as well.
It's extremely common in militaries for specialists to have dual chains of command. In the real world, most officer specialty branches have a dual chain. Engineers, Medical, Personnel, and Chaplain all answer to dual chains, and in all cases, can¹ override the Captain if a standing order from Branch would be breached by the Captain's orders.
The Enterprise is not attached to a particular sector; it's apparently attached to a specific fleet of rovers. Given this, there's a Fleet Surgeon, probably a low seniority admiral, who is her direct medical supervisor. This person answers to the Starfleet Medical Command, including her commanding admiral and vice commander. All three of whom can inspect on a whim, in person or by proxy.
It's really not uncommon for a major command to have a flag officer conduct their own inspections as an excuse to get away from the desk, provided other duties permit.
Dr. McCoy could have opted to do the inspection as a matter of escaping his desk-duty, essentially, a "working vacation." His comments to Data imply this kind of task - filling in a required inspection early, and doing it in person because he wanted to.
Footnotes
¹: Can, but not Must. If, however, things go bad, "just following the Captain's Orders" will NOT protect the senior watchstander when they came through. He and the Skipper will face charges side by side.