Here's how it actually happened:
* The Basilisk was kept in the Chamber of Secrets. This chamber was a secret space within Hogwarts, hidden from most students and staff.
* The Basilisk could move through the Hogwarts plumbing system. The pipes were likely old and poorly maintained, allowing the Basilisk to navigate them. This was a way to reach different parts of the castle without being seen.
* It didn't always travel through the pipes. The Basilisk could also move freely through the castle when nobody was around, as seen when it attacked Ginny Weasley in the bathroom.
Therefore, the Basilisk did not come out of pipes to petrify people. It used the pipes as a means of travel within the castle, but could also move independently.