That rests on assumptions. For one thing, the range necessary will depend on the range of the dragon, i.e. of the dragonfire. And actually, it makes sense to me that you wouldn't get a continuous stream of fire that is longer than ballistae or scorpions can shoot? So yes, if they want to attack instead of just playing aerial surveillance, the draogns will have to get in range. In fact, dragonfire probably has such a shorter range that they will probably have to get in range of several scorpions, if the castle has several. And if you have several scorpions aiming at the dragon, then you will eventually get at least one with a good angle, instead of firing "upwards".
I mean, it's a dragon, not a B-52 bomber. It will not stay above the clouds and release fire straight down. If it wants to attack, it will have to come close to the castle and probably can't stay a perfect 90° above the target at all times. And then with several scorpions, it will be in the angle of several scorpions, too.
Once again, AWOIAF specified "scorpion". I.e., a
light ballista that can be operated by a single man. I am not sure where you get the idea it has to be this huge thing with counterweights and everything; a scorpion is a pure torsion engine, without trebuchet counterweights, and not even man-high. A light siege engine, of which you can easily put a dozen on your walls if you are specifically preparing for a dragon attack.
So this is another false assumption you rest your argument one. Now of course, the reason why a small, light siege engine was enough is because it was a lucky shot. If we go by how Tessarion died, and by Tyrion's books, most likely Meraxes was shot in the eye. It might even be a normal
arrow to the eye is enough to kill a dragon, though granted, Tessarion was already dying when she was put out of her misery that way, so we can't know for sure. But a bolt to the eye, absolutely a way to kill a dragon, because apparently dragon eyes are vital organs or something.
Now,
@Eternal_0bserver 's argument about dragons being a moving target, that is a much better argument here: Light siege engine or not, a scorpion still is not nearly as agile as a bow and has worse reloading times than a crossbow - and you are trying to hit a moving target and that ideally in the eye. So "one in a million shot" seems apt for how Meraxes was taken down.
However, I will note that we have no real idea how dragon fights work. While there have been aerial dragon to dragon fights, most of them seem to have been decided by melee (i.e. claws and bites). This will only help so much against a castle, or a unit of people. So, I think we can't say for sure how mobile you actually can stay as a dragon
while attacking with dragonfire.
Which means - yes, it was a lucky shot, but stocking your castle defenses up with scorpions and hoping for that lucky (but by no means impossible or even just miraclous) shot, that might still be a reasonable and deliberate strategy against dragons, instead of lucky happenstance.