The U.S. Flag Code addresses the civilian population, rather than the military. The military has its own flag code, and it may vary somewhat between the branches of the armed forces.
Section 5 gives us this text (quoted in its entirety)
Sec. 5. Display and use of flag by civilians; codification of rules and customs; definition
The following codification of existing rules and customs pertaining to the display and use of the flag of the United States of America is established for the use of such civilians or civilian groups or organizations as may not be required to conform with regulations promulgated by one or more executive departments of the Government of
the United States. The flag of the United States for the purpose of this chapter shall be defined according to sections 1 and 2 of this title and Executive Order 10834 issued pursuant thereto.
By the time the current rules and regulations were codified, the civilian population was looking for guidance in flag protocol. In 1924, the materials we call the U.S. Flag Code had been gathered together into a body of work.
Congress adopted the code in 1942, with some refinements added at later dates. In 1959, Dwight D. Eisenhower updated the code to include 48 stars on the blue union. He signed Executive Order 10798 on January 3, 1959. That was the last major revision to date.