Some iPhone 5 units were reportedly shipped out without the battery being properly set. This made the iPhone rattle on the inside when users tried to use the phone. This problem was experienced by early users but it diminished with later sales.
Solution: Take it to the Apple Store
The rattling will be quickly fixed by Apple Care personnel, so take it to the store. If the problem is not fixed, they will replace the phone.