Actually the second_stack is used here as the reversed form of the stack.
To my understanding, as long as the stack has a peek - it is placed at the top of the second stack.
So, when we would like to pop an element from the queue, we approach to the second stack - popping its "upper" element up.
When we would like to push an element to the queue - we just enqueue it to the first stack - its turn will be soon as the second stack happens to be empty again.