Game feel. A bounce that always goes the same way is boring. Letting the player aim with the paddle turns a toy into a game.
Keeping the speed. With math.hypot we measure the speed and with math.sqrt(speed**2 - dx**2) we compute the vertical part, so the speed never changes by accident.
Edge cases are tests. A rising ball passes through the paddle, a ball beside the paddle misses it and a ball below the paddle centre does not count as a hit. Each case has its own test.