In addition to James K's answer, many gases exist in the disk of material that forms into planets. What's a gas as opposed to a liquid or solid also depends on temperature and pressure. The most abundant "gases" in our solar-system are hydrogen, helium, CO2, H2O, CH4, NH3, N2, O2, CO, Neon (and maybe some others I've overlooked), in something sort of close to that order. Many of these "gases" are also ices that form up the majority of comets.
During planetary formation, the ring of debris is too warm for hydrogen, Helium and Neon to be anything but a gas, though some hydrogen is bound to heavier elements and abundant in planet formation. Helium and Neon and the other Noble Gases don't bind well with other elements.
The other abundant "gases", H20, CO2, NH3, CH4, etc, can exist as ices past their respective frost lines. That's why those molecular compounds are much more common in the outer part of the solar system.
Earth and Mars formed inside the frost-line so they formed mostly out of rocky material, after which, much of the lighter elements, primarily gases and liquids, were acquired by comet impacts after formation, though some probably existed prior too formation.
During the late heavy bombardment there were many large impacts and one consequence of very large comet or meteor impacts is a rise in temperature, so, even in the early solar-system when the sun wasn't as luminous as it is now, the planets, Earth and Mars spent some of the time quite hot.
There's two primary ways a planet can lose it's atmosphere, Jeans Escape and by the solar wind.
The solar wind is made up of almost entirely charged particles, so if a planet has a magnetic field, the impact of those high speed particles is largely deflected, where as, if they impact the upper atmosphere, the planet can lose it's atmosphere like tiny billiard balls being knocked off one at a time.
While the method of those two ways a planet can lose it's atmosphere are different, it comes down to basically the same thing. When gas molecules on the outer edge of a planet's atmosphere move faster than escape velocity they are likely to escape the planet into space and because lighter gas molecules move faster than heavier ones. That's the Maxwell-Boltzmann law or Root-mean-square formula, planets are more likely to retain heavier gases.
Venus and Mars have both lose most of their lighter gases, H20, CH4, NH3 but CO2 is heavy enough to have been retained by both those planets, though it's worth pointing out that we don't know how much CO2 Mars had millions and billions of years ago. Mars may have lost much of it's CO2 over time as well. It just lost it more slowly than the lighter gases. Mars was able to retain some of it's water, however, in the form of ice.
Venus, like Mars, lost nearly all of it's gaseous water. We know that Venus used to have much more water because it's very high D to H ratio wouldn't be possible unless it had lost a significant percentage of it's water, likely 99.9% or higher.
Earth is massive enough and Earth has a strong magnetic field, so Earth is able to retain it's lighter gases like CH4, NH3 and atmospheric H20, though Earth loses Hydrogen and Helium to space. NH3 is kind of interesting because it dissolves in water quite readily, so as soon as the young Earth had oceans, those oceans were likely Ammonia/water with whatever else readily dissolved in the liquid such as Iron. The early oceans are thought to have been brown colored from the dissolved Iron. But Earth's young atmosphere was likely mostly CO2 and CH4 with most of the H20 in liquid form, (and at times, much of it was ice).
As life and photosynthesis began releasing Oxygen, Oxygen readily bonded with the CH4 and dissolved Iron in the oceans, turning the oceans blue and in time, making the Atmosphere free of CH4 and more abundant with O2. It's unclear (and perhaps unlikely?) if Mars and Venus ever underwent that Oxygenation period that Earth did. Having abundant liquid oceans and having photosynthetic life made a significant difference to Earth's atmosphere.
You mentioned plate tectonics and that plays a role too as does the chemistry that happens in the oceans and below the surface of a planet. The main reason Mars is 95% CO2 now is because it's small and it doesn't have a good magnetic field, only small localized ones. It lost most of it's atmosphere and nearly all of it's lighter gas molecules.