Why was the atmosphere of the Earth formed?
To support life! The atmosphere was formed by accident, just by the process of Earths creation.
The atmosphere was formed back during Earths creation! When the Earth first formed there was a mix of gases and solids, and no atmosphere! The surface of Earth was really hot and molten. But as it cooled the atmosphere was formed through the gases spewed our of volcanoes.
These gases were hydrogen sulfide, methane, and a whole bunch of carbon dioxide (way more than whats in our atmosphere today). After about 500 million years, Earth cooled down and solidified enough for water to collect on it.
And voila, the atmosphere had formed! Under just perfect conditions for life to form :)