How does this trick with mirrors work?

The reason is simple geometry. Consider the following image.
(source: tutorvista.com)

Then you can clearly see the image at $O_{3}$ is due to double reflection from mirrors $M'$ and $M$. In general all the images including the object will be on a circle centered around the intersection point between two mirrors. For two mirrors inclined at $n^{0}$ with respect to each other.The number of images are $\frac{360}{n}-1$. I do not know the proof of the last formula. As far as I know it is because reflection of one mirror to another forms a virtual mirror and the number of virtual mirrors are $\frac{360}{n}$ http://www.learnquebec.ca/export/sites/learn/en/content/curriculum/mst/images/CHAPITRE523.GIF Final image from both the mirror coincides hence we have to subtract $1$.