There are two main main circumstances in which individual officials are named.
One is where the relief sought is non-monetary and the official has the ability to provide the relief, such as a habeas corpus action, which names the warden of the facility having custody of the individual bringing the action, or an action to has an official interpret a statute in a particular way by someone regulated by the statute. Usually, it is an action for an injunction, declaratory relief, or a writ compelling an official to do or refrain from doing something.
The other is a Bivens action seeking to hold a government official responsible for misconduct in money damages, akin to a Section 1983 lawsuit against a state or local government official, although this is arguably not an official capacity lawsuit.
Until the federal rules of civil and criminal and appellate procedure were amended in the late 20th century, interlocutory appeals from a judge's decisions (i.e. from orders entered before the case was completed) were structured as lawsuits brought by the appealing party against the judge in his official capacity seeking a writ under the All Writs Act, ordering him to change his order. But, this procedural nuance has been reformed in the federal courts and many state courts which instead now provide for these requests for relief to be structured as appeals of an order just like a final order, but under a different court rule authorizing certain interlocutory appeals.
Cases brought in the U.S. Court of Claims seeking money damages from the United States where sovereign immunity has been waived or does not exist are brought against the United States.
Claims in U.S. District Court seeking a refund of tax money paid are brought against the United States.
Cases seeking to adjudicate title to property in which the United States government may have an ownership interest are brought against the United States.
Counterclaims in cases brought by the United States against a person are brought against the United States.
Cases against a specific independent government agency (e.g. AMTRAK a.k.a. the National Railroad Passenger Authority, the Tennessee Valley Authority, the U.S. Postal Service, or the CFPB) are brought against the agency, either if the government agency in fiscally independent of the U.S. government as a whole so money damages come from the agency alone, or where there would be an official capacity suit if the person who could afford relief was a single governmental official in charge but for the relief requested only the multi-member board running the entire independent agency can make the decision, or in a counterclaim to an action brought by the agency against someone.
It is better practice not to sue an agency or office of the United States which is not an independent agency, for example, the U.S. Justice Department, when the United States should have been the defendant. But, often this defect in naming a defendant is overlooked when someone sues, for example, the Justice Department for money damages in the U.S. Court of Claims for failure to pay a court reporting invoice, or sues the IRS in District Court seeking a tax refund, if it doesn't lead to any confusion.
Agencies of the United States proper without separate corporate existence may not sue each other (e.g. the Justice Department may not sue the Labor Department), although this has been attempted more than once in some high profile cases by federal government attorneys who aren't very sharp when it comes to procedural issues, to the consternation of the judges involved.
I'm not sure that there is any one convenient place where this is written down. Instead, it is spread piecemeal over case law in many different places.
There are also probably special cases and exceptions that I haven't mentioned, but the cases I've mentioned are the most common and obvious ones. Perhaps one of them explains NFIB v. OSHA, for which I have no good explanation.