Golding was trying to show that mankind has an inborn defect that most people hold in check to some degree because society and civilization require us to do so. Golding wanted to show that people have an evilness within them and what kind of person each is depends on how successfully each person is at holding that evilness inside. The boys of the story are friendly with one another at first because they don't know one another well and they haven't yet established a pecking order. Also they are friendly at first because no one appears to have what someone else wants. Everyone is equal. By the end of the story, the boys have descended into savagery because most have let the beast inside go. The older boys, especially Jack, have established themselves as leaders with the power to rule over the younger boys. They steal Piggy's glasses in order to have the power of fire. They have established territories and rituals. In Golding's view, the island and the boys on it are a microcosm of the world and of mankind in general. Simon, the mystic, the one who sees what the real beast on the island is, must be killed to keep the secret of the beast's location withheld. Piggy, the voice of reason and intellect must be killed because savagery cannot flourish with reason and intellect. The boys go from friends to enemies because Golding felt that was the nature of mankind - to go from friends sharing the planet to enemies wanting what the other has and wanting power.
In the second link it explains how thoughts were changed after WWII. Before the violence of the war, most believed in the goodness of people and the world. However, after the war, Golding had a completely different viewpoint. The destruction and violence brought on by the war gave us a new concept:
"The prevailing concept of man and society included two basic viewpoints: man was essentially good and society was inherently evil."
This explains your question quite well. In the beginning, the boys all got to know one another and after establishing some rules and a leader, things were going pretty well. In the beginning, each boy showed good traits. Ralph led to the best interest of everyone, Piggy was helpful with his scientific knowledge, and Simon was always willing to help out wherever he could. Yet, they all fell victim to the evils of mankind. Jack and Roger represented the evil (in different ways). Their tribe evolved into a violent machine. It ended up killing Simon and Piggy. It would have killed Ralph had they had enough time. So Golding is showing that although man (each boy individually) has the capacity to be good, society (their tribe) was inherently evil. We see this today in mobs of people. Individually, people are good. However, once a big group gets together with a common goal, violence can occur and things can go horribly wrong.
The writer is trying to show a representation of society. He shows reasons for the evil that exists in society-fear, ignorance, jealousy, etc. He is showing what people can be like when put in certain situations and he is saying that there is a cruel "beast" inside of every person, and we have to learn to control it.