The first problem is that your attackers are way stronger than your defenders.
Orcs are CR 1/2. Ogres are CR 2. Hobgoblins are CR 1/2.
There are 1000 of them, so 500-600 total CR.
Your defenders would have to be all
Veterans or
Knights to stand up against that plausibly if the attackers had siege weapons to nullify defences (and they do; the dragons).
---
So the Dragons will want to use the cannon fodder as fodder. It is possible for them to be felled by mortals; so they'll waste the fodder. The fodder will need help; use the dragons as siege weapons, to get the horde into the castle/defences.
Dwarves in most worlds are engineers. So ballista, including anti-air ballista, and catapults, and other stuff. If it fits, even anti-air cannons.
Troops in this era
scale linearly. We are used to troops scaling quadratically, because we have high powered "if I see you, you die" weapons with near line-of-sight range. But in the ancient era, combat was mostly one-on-one with formations that kept you from being overwealmed.
Anti-archer technology would exist on military scales -- shield walls, pike formations, armor that was proof against long-distance military bows. You can even have military wards against missile fire if you want (to prevent the pincushon effect).
Battle Standard:
This Battle Standard is emblasoned with the sigil of a military unit. While openly wearing the sigil any number of creatures can attune to a Battle Standard.
The Battle Standard creates an aura of 50' radius when held aloft by someone attuned to it. So long as at least 100 creatures are attuned to it within this aura, all ranged attacks by ranged weapons or spells on an attuned creature pick a random target within the aura, the attack roll is disadvantage, and attuned creatures have resistance to its damage. In addition, while they are in the aura, all creatures attuned to hit have advantage on saves against fear and charm effects.
If a Battle Standard falls in battle, a creature not attuned to it can pick it up and become attuned to it at the cost of a HD as an action. Unless an hour has passed, or it is held aloft again, all creatures attuned to it have diadvantage on all saving throws and all attacks.
---
(This actually emulates closer how deadly ranged weapons are in real combat; they aren't as nasty as they are in 5e)
Note that siege weapons are not "ranged weapons"; they are a member of a different category. So your ballista will still be useful.
Ancient red dragon breath (DC 24 so +14 attack) vs 100 random (+4 dex save so 14 defense)
View attachment 120434
Your save math is wrong; meets it beats it swings it by 2.
Or, spell attack is DC-8, so 16. Spell defence is save bonus
plus 14, so 18.
Not much difference as it still hits on a 2.