As with any questions about (classical) motion, think about what forces are involved. Once you throw the ball in the air, what forces act on the ball? What forces act on you?
There's gravity, pointed vertically downward. There's some air resistance pointed in the opposite direction of motion (so down while the ball is going up, and up while the ball is going down). And that's it.
Now for you. You're in the chair, so there's some gravity down. And a chair normal force upwards to hold you still. What other forces act on your body? It depends on if the train is accelerating or not.
So -- all the forces on the ball are vertical. If you're not accelerating, all the forces on you are vertical. Hence the ball falls back into your hand. If you're accelerating, there's a horizontal force on you that isn't on the ball. So the ball moves horizontally relative to you (or in the frame of the ball, you move away from it because you're accelerating).
Always think about the forces. Always draw free-body diagrams.