The returned phones are disassembled in a factory, and remanufactured. Outer cases are replaced (the alumnimum and glass can be recycled), and if there are any defective components, those are swapped out.
Then, they become white box models, for warranty and service exchanges.