The pasuk implies that Yosef initiated everything that was accomplished by the prisoners. The redundancy of the text begs explanation. Obviously, everything they did he would do. Horav Moshe Yechiel Epstein, z.l., interprets this pasuk homiletically. Yosef was teaching us a profound lesson in avodas Hashem, serving the Almighty. Yosef was not satisfied with the fact that he upheld all of the mitzvos. He was not complacent with his own mitzvah observance. He was driven to do more, to correct and complete what others had either denigrated or discarded. Yosef was not content simply to abstain from transgressing any aveiros, sins; rather, he further sought to perform mitzvos which could deflect the effects of the aveiros of others. Yosef’s name is derived from the Hebrew word “to add.” Yosef added on to his own mitzvah observance; he was constantly “doing” good deeds.
Yosef reflected upon the “doings” of the evil Egyptians, and he countered their actions with his mitzvos. For “whatever they did,” he would do the opposite. His positive action in performing mitzvos filled a void left by the behavior of others.