Doors let people in and out, or sometimes just in. You can’t always trust doors; some only go one way, and then you’re trapped with no way out.
The Pandorica is like that; it’s a prison, designed to keep someone in; to get out you need outside help, which the Doctor has. All it took was a bit of time-hopping by his future self.
Rory opens the Pandorica to let the Doctor out, and when it closes again, Amy is inside. It’s meant to be the perfect prison; now it’s going to save a life, and maybe the whole universe.