What is wrong with this reasoning?
It is based on a false assumption of how light works.
The photon is directed exactly in the same vertical direction as the ball, but as it has no mass it is not being carried away by the motion of the box, and seen from a stationary observer its path will not be tilted toward the front but vertical.
This simply isn’t how light works.
Consider, for example, the following arrangement: there is a tube, mounted vertically in the box for launching the ball in a straight line vertically. Attached parallel to this tube is another tube. This second tube has a spherical point light source in the center of a cap on the bottom end of the tube and a small hole (barely large enough that diffraction is negligible) in the center of a cap on the top end of the tube.
The ball is launched and leaves a spot on the ceiling above the launcher.
The spherical light source pulses, most of the light is absorbed by the tube, except for the light that hits the pinhole. That bit of light continues on that straight line and hits a spot right next to the mark from the ball.
The whole assembly is gently accelerated to some velocity, at which point it moves inertially. The experiment is repeated. In this frame the ball moves diagonally with the tube, travels diagonally as the room moves, and makes a mark in the same spot on the ceiling.
The spherical light source pulses, most of the light is absorbed by the tube, except for the light that hits the pinhole which is the light that moved diagonally at the correct angle. That bit of light continues on that diagonal line and hits the same spot right next to the mark from the ball.
So light does not behave as you described. There is no optical detection of absolute motion