What can cognitive psychology tell us about the results of the Stanford Prison Experiment? One of the experiments that are always taught as prime examples of social psychology in action is the Stanford Prison Experiment

In 1971, Zimbardo accepted a tenured position as professor of psychology at Stanford University. With a government grant from the U.S. Office of Naval Research, he conducted the Stanford prison study in which 24 normal college students were randomly assigned to be &quot;prisoners&quot; or &quot;guards&quot; in a mock prison located in the basement of the psychology building at Stanford (three additional college students were selected as alternates, only one of which participated in the study). The two week planned study into the psychology of prison life ended only after 6 days due to emotional trauma being experienced by the participants. The students quickly began acting out their roles, with &quot;guards&quot; becoming sadistic and &quot;prisoners&quot; showing extreme passivity and depression.
*from the Philip Zimbardo article

I realize there have been scores of scholarly articles written about the subject in the intervening time, but most of the abstracts dealt with the aspects of social psychology that were pertinent even in the last decade with the atrocities at Abu Ghraib.
All of that is painful yet certainly necessary to ponder, but I'm curious about the cognitive aspects of the study.  What facets of, for example, motivation does this study (and others like it) bring out?  What can be said about our sense of logical reasoning under these circumstances?  What sorts of qualia could one use to model this behavior in an agent?
I've always thought of Stanford Prison Experiment (and Abu Ghraib) as a situation in which group think forms a sort of feedback loop. If you agree that people behave within context of a group, and the context is created by the group itself (Hogg, 1998), then you can see what is happening. The context may at first be in line with the larger group (the University, or Military, or American culture in general). Within the smaller group however, individuals may "push the limit" of acceptable behavior. But in doing so, they are changing to context of the group. For a person to "push the limit" again, would be to act in an even more extreme way. The situation feeds back upon itself.

The question remains, as you pointed out, what motivation starts this movement in the first place? There is no reason to think it couldn't feedback upon itself in the other direction, either. There is some underlying feeling that is amplified by this group think. In the Hogg article, the researches essentially seeded that motivation experimentally. But in a normal situation, it can be virtually anything. Intuitively, I would say in the prison experiment the initial seed was just a desire for the students to act out the roles they were given. Prisoners obey the guards. Each time the limit of acceptable behavior was pushed, the context that defined acceptable behavior was changed too. 

Myers (1977) describes something similar, which he calls polarization. In his research, he showed a tendency for people to not only conform to the group standards, but also try to exceed them in, "the socially preferred direction". This phenomena, plus a tendency to act within the context of a group, can lead to runaway behavior.

References

http://psycnet.apa.org/journals/gdn/2/1/48/

http://www.sciencedirect.com/science/article/pii/0022103178900495