Yes, it is legal. The FAA's guidance document for formation flight (short document, easy read) mentions standard formations, and it states:
c. After join-up, aircraft beacon code assignment will be determined by formation type.
- For a standard formation only the aircraft acting as the lead will squawk an ATC assigned beacon code. Ensure all other aircraft squawk standby.
There is also FAA Order JO 7610.4 regarding special operations, on which the guidance is based, but that document is only available internally from within the FAA network.
If you intend to fly within Class C airspace or within 30 nm of any airport in 91.215 Appendix D, you will likely needhave to contact ATC (as you would to ask for flight following) to deviate from the requirement that all pilots squawk VFR. Arbitrarily deviating from the transponder rule in Class C without getting permission from ATC would likely be judged in violation of rule.