Here's how it happened:
* Ron Weasley, under the influence of a love potion, accidentally dropped the cup into the Room of Requirement.
* Harry Potter, having discovered the cup was a Horcrux, realized that he needed a basilisk fang to destroy it. He managed to retrieve one from the Chamber of Secrets.
* Harry and Ron then used the fang to destroy the cup, fulfilling one of the steps in their quest to defeat Voldemort.