Instructions
Play through the game until you reach the Astronomy Tower and the battle with Crabbe and Goyle. Find the key once the battle is over. It is a large white object that is in the center of the room.
Cast "Wigardium Leviosa" on the key to break it into pieces against a wall. Cast "Wigardium Leviosa" again to levitate the pieces through the gate.
Cast "Reparo" on the broken key once it is outside of the gate to put it back together. Cast "Wigardium Leviosa" on the key to levitate it into the slot outside of the gate to open it.