Sodium and potassium form peroxides and superoxides upon combustion due to the energetics involved in their reactions with dioxygen. The formation of these compounds is more thermodynamically favorable than producing standard metal oxides. This behavior is particularly pronounced in potassium, which tends to form superoxides more readily than peroxides. The underlying chemistry reflects the unique properties of alkali metals and their interactions with oxygen, leading to a variety of products beyond just metal oxides. For a detailed explanation of these reactions and the behavior of Group I elements, resources like Chemguide provide valuable insights.