Will the ball come out of the well or not?

Looking down from the top you can see the symmetry of the situation with the ball hitting a wall in a time interval of $\dfrac {2 r \cos \theta}{v}$ and for vertical motion the ball again reaching the rim in a time $2 \sqrt{\dfrac {2H}{g}}$ (using $s = \frac 1 2 g t^2$).

enter image description here

So you must have $\dfrac{2 n r\cos\theta}{v}=2 k \sqrt{\frac{2H}{g}}$ for the hitting the wall and reaching the maximum height to occur simultaneously where $n$ and $k$ are integers.


Later:

If the ball is a point mass and arrives right at the top of the wall it will not hit the wall and rebound but will continue moving in a straight line and so escape from the well.


the only way for the ball to escape is if it bounces a number of times and it reaches the edge at the top of a bounce. This condition means that the horizontal time flight must be a rational fraction of the vertical time: $t_h=\frac{m}{k}t_v$, which includes all possibilities, including coming back to the initial point, or getting out through the other side, hole large enough to allow several horizontal bounces, or too small to allow one before bouncing on the wall before touching the floor.


enter image description here

Take a 2D case for simplicity. Suppose the ball entered the well at point A. It did hit at points R1, H1, H2 and R2 so lucky that exactly fit point B thus gone out. This happened only because ratio of diameter to depth of the well is so good that allowed the ball to do finite number of bounces. This is possible because time needed for vertical travel with some number of bottom hits (let's say, Tk) is exactly same as time taken for the other number of horizontal hits with the wall (Tn). In unlucky case if you can't divide one time by the other and get an integer, then the ball would get into infinite loop inside the well.