There are two main reasons why the planets have different atmospheres.
The first is because of the way the Solar System was formed; 4 and a half billion years ago it was formed from a big swirling ball of gas and molecules. At the centre, the hydrogen and helium collected together to form the Sun, and started the nuclear reactions in it which are still happening which is why the Sun is so hot. Around it, all the other materials formed a rotating disk, which eventually lumped together into planets at different distances. The disk did not have the same amount of molecules and elements everywhere, so the planets that formed have different compositions.
As the planets closest to the Sun were forming (including Earth), some of the lighter gases around those planets were stripped away by the Solar Wind (but not for planets further away, the big gassy giants). Volcanoes on the inner rocky planets released gases inside the planet. Because each planet is made of different materials, different amounts of gases would be in the atmosphere.
Secondly, is the Goldilock effect. The Earth is often described as being in the ‘Goldilock’ zone (or Habitable Zone) because it is at a distance from the Sun which is not too hot and not too cold for life, and for our atmosphere.
Mercury is too hot to have an atmosphere – all the molecules released from volcanoes would be heated up so much they would have enough energy to escape the planets own gravity. Venus too is impacted by the Sun, although it is not too close for the gases to escape, the heat has caused a ‘run-away Greenhouse effect’. What has happened is that water initially on the planet was always too hot to become liquid, and so formed lots of clouds. This meant that heat from the Sun couldn’t escape and so the atmosphere got hotter and hotter. The carbon dioxide which was trapped in the rocks was heated until it also turned into a gas and caused the planet to have even more clouds, making the situation worse until the planet ended up with the very thick clouds that there are now.
On Earth, the amount of energy coming in from the Sun and being lost to space is about the same, meaning that the planet can stay at a constant temperature. Our atmosphere, although starting from gases from volcanoes has changed by the presence of life, and photosynthesis producing oxygen to the level it is now.
Mars, conversely, is further away and colder. It has a thinner atmosphere, in part caused by a reverse greenhouse effect (molecules condensing into the rocks), and also possibly because the planet was too small to hold onto all its gas. Future missions to the planet by spacecraft are hoping to investigate this further.
So, the answer really is that it is a combination of what the planet is made out of, and where in the Solar system it was formed that has determined it’s atmosphere. The interesting point is that atmosphere’s have changed in the past, and so could change in the future, and by understanding how our own Solar System was formed and works we can better understand the solar systems we are seeing around other suns.