Carbon dioxide is supposed to be the "normal" atmospheric composition of a terrestrial planet. This generalization might seem wrong at first, because only a couple of planets follow it. Mars and Venus have CO2 atmospheres, but the Moon and Mercury have no significant atmospheres, and the Earth has a nitrogen and oxygen atmosphere with very little CO2. But let's look more closely at the physical conditions on each planet. All of the terrestrial planets (and the Moon) started out warm enough to have volcanism, as we can see from lava plains on the Moon, Mercury, Mars, Venus, and Earth. When volcanoes erupt, they emit carbon dioxide and water vapor gases. So the natural by-products of molten terrestrial planet interiors are CO2 and H2O gases.
Volcanoes, however, aren't the only thing impacting the atmospheric compositions. The Moon and Mercury are small and have weak gravity, so they lost their original atmospheres over time. Energetic photons from the Sun can break H2O molecules into separate H and O atoms. These light weight elements are subject to huge accelerations when they are impacted by molecules. Hydrogen has an atomic weight of 1, oxygen has a weight of 16, water vapor has a weight of 18, and carbon dioxide has a weight of 44. From the kinetic theory of gases, we know that in a mixed atmosphere of gases, light atoms or molecules can collisionally be accerated to high velocities — even to the escape velocity of their host planet. So we would expect H to escape easily, and CO2 to be retained. We can combine this principle with the chemical properties of gases to explain why the terrestrial planets have such different atmospheres.
On Venus and Mars, the H2O was broken down, leaving CO2 molecules behind. If water molecules are broken into H and O atoms, the hydrogen quickly leaks away, and the water molecules can't re-form. The O atoms left behind do not accumulate in the atmosphere, because they are so reactive. Instead, they react with surface minerals, oxidizing them, and end up trapped in the rocks and soil. This was how the iron minerals on Mars were oxidized, producing the planet's characteristic rusty color. Any water in the Martian atmosphere that didn't break up and escape was frozen into the polar ice caps and permafrost layers beneath the surface.
Mars and Venus both have CO2 atmospheres, but they are very different thicknesses. Venus's atmosphere is about 90 times as thick as the Earth's, while the atmospheric pressure at the surface of Mars is less than one percent of that on Earth. The difference between the atmospheres is mainly due to the planets' sizes; Mars is smaller, and its gravity was too weak to retain more than a thin CO2 atmosphere.
Earth's atmospheric evolution broke from this standard pattern. Unlike the other planets, it is at just the right temperature for H2O to condense into liquid water and form oceans, instead of remaining gaseous in the atmosphere. Once liquid oceans were present, CO2 readily dissolved into them, forming a weak carbonic acid solution. The carbonic acid reacted with rocks to form carbonate mineral deposits. This process removed huge amounts of CO2 from the atmosphere and deposited it as rocks. Once the CO2 was removed, or scrubbed, from the planet's atmosphere, the Earth was left with an unusual atmosphere of mainly nitrogen (N2), which would otherwise have been an obscure trace gas. Note that N2 is a heavy gas, with an atomic weight of 28, so it is easily retained by the Earth's gravity.
There is an elegant test of this explanation for the uniqueness of Earth's atmosphere. Earth and Venus are similar in size, so they should have originally produced similar amounts of CO2. The CO2 would be in the atmosphere on Venus, but trapped in rocks on Earth. Scientists have made inventories of the total amounts of CO2 contained in terrestrial rocks, and they found that the Earth has almost exactly the same amount of CO2 in its rocks as Venus has in its atmosphere.