Two recent questions and their answers have raised a further question.
In Are there laws about how close military aircraft can fly to passenger jets, and are they enforced?, we learned that "the military can get as close to other aircraft as they damn well please, through a procedure called Military Assumes Responsibility for Seperation of Aircraft, or MARSA".
In Why are there NASA branded F/A-18s? we see a picture of closely flying planes, and a comment notes "NASA is a civilian agency".
Do the NASA planes fly under MARSA rules or another set of rules for civilian agencies? Are there other non-military agencies that fall under this rule too?
Pilots are allowed to fly as close as they want to each other as long as all parties agree to it and feel safe doing so.
Air Traffic Control cannot guarantee separation for planes in formation flight,So this will only be done under VFR and in VMC, where pilots can maintain visual separation from each other.
Many stunt fliers are civilian pilots and will routinely fly in close formation as well.
Other notable example of civilian formation flight include Mythbusters testing airplane fuel efficiency in formation and Airbus' publicity stunt with 5 A350s
You already have a good answer on separation specifically, but it's worth noting that there are a few general rules about formation flights in 14 CFR 91:
The most specific formation rules are in 91.111:
§91.111 Operating near other aircraft.
(a) No person may operate an aircraft so close to another aircraft as to create a collision hazard.
(b) No person may operate an aircraft in formation flight except by arrangement with the pilot in command of each aircraft in the formation.
(c) No person may operate an aircraft, carrying passengers for hire, in formation flight.
Charity flights are exempt from air carrier (part 119) and drug/alcohol testing (part 120) requirements, but only if the flight is not a formation flight (among other conditions):
§91.146 Passenger-carrying flights for the benefit of a charitable, nonprofit, or community event.
(4) The flight is not an aerobatic or a formation flight;
You must provide formation details if you're filing a VFR flight plan:
§91.153 VFR flight plan: Information required.
(a) Information required. Unless otherwise authorized by ATC, each person filing a VFR flight plan shall include in it the following information:
(2) The type of the aircraft or, in the case of a formation flight, the type of each aircraft and the number of aircraft in the formation.
(3) The full name and address of the pilot in command or, in the case of a formation flight, the formation commander.