What is the function of the atmosphere?
It sort of doesn't.
Using the word "function" implies that it exists to serve a purpose, which is sort of like asking what the function of a rock is. It has many properties that allow it to support life and to cause weather, but if you are looking for a religious answer I am not qualified to answer. I will provide an answer that states what purposes are accomplished due to the properties of the atmosphere.
The atmosphere is the envelope of gases that surround the Earth, and remain there due to the gravity of the Earth. It is divided up into layers (spheres) that each have some unique properties. The main ones for humans are the Troposphere and the Stratosphere.
The Troposphere is the layer of the atmosphere closest to the Earth and it goes up anywhere from 28000ft to 70000ft depending on where you are on the Earth and the temperature of the Earth. This layer is of prime importance to us as it is the part that surrounds us (providing oxygen) and causing the vast majority of the weather (also the main mover of the water cycle).
The Stratosphere is the next layer (the transition layer between the Troposphere and the Stratosphere is called the Tropopause), and it is very important because apart from a small amount of weather (hurricanes and very big thunderstorms and grow up this high), it is where the ozone layer is. The ozone layer is a layer where a lot of ozone is found, and ozone blocks UV light which can be very damaging to animal cells.
It is a mistake to think that the atmosphere serves to protect us from Cosmic Rays or Solar Wind. These high energy particles are blocked by the Van Allen belts which are magnetic bands that surround the Earth and are independent of the atmosphere.