The reason Carbon and Nitrogen are rare on Earth compared to their abundance in space is because elements containing carbon and nitrogen didn't survive the heat of the sun at Earth's distance during the protoplanetary disk stage. Carbon can form carbonate rock, but only under certain circumstances. Carbonate rock is rare in space and most of the carbon is in the form of Carbon dioxide.
Oxygen, unlike Carbon or Nitrogen, bonds readily with Silicon, Magnesium, Iron and other heavy elemets, which is why Oxygen is very abundant in rocky planet formation. It's one of the elements abundant in space-dust, unlike CO2, H20, CH4, NH3, which can form, in colder regions, ice or snow like formations as they begin to clump together, but only in cold regions of space.
The sun didn't precisely have an "event", though young stars after formation can be much more violent. The initial heat of formation can be very bright and very hot, and young stars are usually rotating very fast and prone to much bigger solar storms and very large mass ejections. Pretty much all stars go through a violent youth. It's not a unique event to our solar-system.
Common elements in space, such as CO2, H20, CH4 and NH3 are gaseous at Earth's distance from the sun and as a result, are unlikely to stick to anything in the Earth's formation region. This is true for all 4 inner planets and likely all rocky worlds. Rocky planets likely can only form close to their star, just as gas giants, ice giants or other icy abundant bodies like comets and low-density moons, can only form further out.
Gases like the 4 above can begin to be retained around a planet after it reaches a sufficiently large mass with low enough surface temperature to retain those gases by gravity.
The boundaries where CO2, H20, CH4, NH3 and other gases can be found in the protoplanetary disk is called the frost line. Different gases have different frost lines depending on their freezing point.
It's thought that much of Earth's water, CO2, CH4 and NH3 came to the Earth by comet after the planet formed. There's still some uncertainty on the percentages, as some of those elements could have been trapped during formation.
Just to add, hydrogen and helium are obviously abundant, but will only begin to accrue around a planet of a certain mass. In our solar-system, only Jupiter and Saturn are massive enough to accrue hydrogen and helium. That's why Uranus and Neptune are relatively low on hydrogen and helium compared to the universal abundance.
Argon is in Earth's atmosphere because it forms from gradual radioactive decay of Potassium-40. Earth's Helium is also present as a result of radioactive decay.