It wasn't entirely true that they were free to leave at any time either. If someone wanted to leave they first had to talk with Zimbardo. In at least one case, a prisioner talked with Zimbardo then decided to continue the experiment despite the appearent psychological stress they were under. They went back feeling very confused and actually began a rumor that no one could leave because Zimbardo had asked him if he thought he would be able to continue rather than giving up on the experiment.
The experiment was unethical from the very beginning because Zombardo also gave himself a role as "superintendent", preventing him from being an unbiased observer. He allowed the prisioners to think they were not allowed to leave and the experiment caused lasting psychological harm (although Zombardo denies this). Both of these break psychology's ethical guidelines for dealing with human subjects. This is a short clip of an interview where they brought one of the prisioners and one of the guards together after the experiment had ended. Notice the body language of the two. I would definitely call that lasting psychological harm.