Water stays in the bucket for the same reasons that we stay in our seats when we do a loop on a rollercoaster. Another example is being driven round a roundabout and feeling a 'force' pushing you outwards away from the roundabout.
The cause of this 'force' is known as inertia- which is given by Newton's First Law of Motion: objects will remain at rest or at constant velocity unless acted on by an external force.
As we swing the bucket through the loop, the water experiences a downward force due to gravity, which is accelerating the bucket's contents down towards the ground.
However, the water also has another force acting on it. The sides of the bucket push on the water and cause it to have another acceleration, tangential to the circle the bucket is being swung through. Therefore, at the top of the swing, the water feels a downward force towards the ground (due to gravity) and a sideways force perpendicular to the ground (due to the bucket walls). The resultant of these two forces is a diagonal force, accelerating the water down and along. Thus, the water falls diagonally, where it is caught by the bucket again as it moves through the circle and remains in the bucket!