When two objects collide, they transfer momentum because they exert an equal and opposit force on each other (Newton's third law), and $\Delta p = \int F dt$.
In order to know how fast an object moves after a collision, we need to know the velocities and mass of the objects before the collision and how elastic the collision is (conservation of kinetic energy). For now, we will assume a perfectly elastic collision between ball and bicycle basket. We will also assume the basket is firmly attached to the bike, and that the mass "bike plus basket" is much greater than that of the ball.
Now we can analyze the situation: it is like that of a ball hitting a moving wall. If a ball moves to the right at velocity $v_1$ and hits a wall moving to the left at velocity $v_2$, then their relative velocity is $v_1 + v_2$. Now comes a trick: we look at the collision from the point of view of the wall (really we want to use the "center of mass frame", but since the wall is much heavier than the ball, we can use the wall instead). The wall sees the ball come towards it at $v_1+v_2$, and after an elastic collision it needs to move away at the same speed $v_1+v_2$. This means the ball velocity changed by $2(v_1+v_2)$. That same change must be observed in the "world" frame of reference, so after a collision the velocity is
$$v' = 2(v_1+v_2) - v_1= v_1 + 2 v_2$$
to the left.
In other words - the ball picks up twice the velocity of the thing that is hitting it.
And that is fundamentally what happens for you. The ball bounces around, and if you are unlucky it is moving down just as the basket moves up. The sum of their velocities can be sufficient to throw the ball out of the basket: and if it wasn't, then the ball's $v_1$ will be greater on the next bounce.
Elastic collisions, one mass much greater than the other, and random inputs of velocity from the basket. Those three ingredients are sufficient to explain this.
Afterthought: it is more likely for the ball to hit the basket while their relative velocities are greatest: if you consider the motion of the basket to be truly random, then during the time interval that it is moving away from the ball the rate at which the ball approaches is low: when the basket moves towards the ball the rate is high. So a randomly moving basket is more likely to give additional energy to the ball rather than remove it! In a way it is "designed" to throw the ball out.