If you feel up to adapting a system from an earlier edition, BECMI D&D had the War Machine rules for mass combat, and the Siege Machine extension to those rules for siege warfare, both available in the Rules Cyclopedia (available in PDF from dndclassics.com.)
It ought to be fairly simple to adapt as it's based mostly on things such as average hit dice and AC of troops, so you just need to make an adjustment for the inverted AC of that edition of the game.
Note that War Machine works at the unit/regiment level - imagine a map, with each unit (which could be hundreds or even thousands of troops) represented by a counter with it's own statistics, making it comparable to most historic battle diagrams (1st archers, 2nd archers, 1st Mounted Knights, and so forth), and is designed for play on a hex map of the area (although you could feasibly use a square grid, too.)
Establish PC's goal in the battle
Never forget that the battle has a purpose but your PC's motivation might be different. Are they fighting to help win the battle to save a city? Are they forced to fight and want to survive together? Are they protecting an NPC friend who will fight no matter what? Do they defend their honor after swearing that the right flank will hold? The battle itself cannot be the goal, there has to be a well-defined challenge for the party.
Assure that players have competence to attain that goal
If they are just fighting to win the battle, they need something to differentiate them from a sea of regular troops. They can be commanders or officers, they can have their own cohort to lead or they could just be veterans instilling hope and courage in others. Otherwise they will have no agency.
Conversely if they wish to attain a different goal, such as defending their friend prince from death, they need to be put near him - or have at least a way to reach him.
Treat the battle like a scene that surrounds the players
It's easy to forget that the battle is just another way of shining light on the characters. Your players are assumed to fight near constantly, unless they can manage to disengage the opponents. Do not treat that as combat encounter, but rather as a puzzle that can be solved through leadership, cunning and violence. Instead of having your barbarian use his rage to fuel his damage output, let him burn it as a mean to attain advantage. So, using that as an example if your players protect an NPC - Alice, The Brave Maiden from death in battle, Brong the Barbarian might spend some of his rage to clear an opening to reach her in time.
Make battle events relevant to the players in their own scope
Which means that as the battle is going they seem to hold their own, but when the enemy sends reinforcements, they might have to fight an elite enemy as if it was a standard one-on-one encounter. If they rally their troops to exploit an opening, describe how lowly soldiers ravage enemy lines with their newfound courage. Also, limit their knowledge - they shouldn't have any idea what happens on the other flank, unless party rogue climbs the remains of a catapult to scout the situation.
Ensure party goals can be met regardless of the outcome of the battle
That's pretty straightforward. Give players an opportunity to carry mortally wounded Alice into the forest. If their flank collapses, let them be warned to cast invisibility to escape. If the fortress is being overwhelmed, let them carry the MacGuffin to safety in the nick of time.
Last but not least
Assume they act as a team like they would normally do
That means protecting each other, keeping formation, using their basic fighting skills to attack and defend. Don't force the players to tediously adhere to the battle grid or roll dice all the time. Just assume they are fighting a battle and throw in a juicy description how Cerion the Fighter shield-bashes a particularly large orc and Daria the Mage blasts him into a group of goblins. If you want to portray battlefield attrition, you can abstract their actions to a single "performance" roll, which would penalize them with wounds or depleting battle supplies for a bad roll, e.g. Daria would use one of her spells or Cerion would lose some hitpoints. You may even let them haggle with you to get out of trouble, offering to use up a spell or lose a piece of equipment instead of being wounded etc.
Mass battles usually abstract mobs as if they were single units. You have to do the opposite - abstract all the fighting chaos into landscape events not different from weather or sunset and have particular bite-sized challenges appear from it.
Refer to fictional battles as reference material
And the classic example of that is Battle of Helm's Deep - let's stick to the film version.
The characters have a goal - to protect people of Rohan in the fortress (and to win a kill count contest). They have competence and a role - they are leaders and champions, even though the battle is commanded by Theoden and elvish force by Haldir, they have an influence over troops around them. They fight all the time, but only interesting bits are shown on screen. They only are aware of their immediate surroundings and what happens at the gates is not shown while they are in the keep. They in the end achieve their goal and even if Eomer wouldn't come, they would still have hope for women to escape from the caves. Finally, they meet specific challenges - to hold the wall first, then to kill the famous Torchbearer Orc which fails, then to hold an opening for the elvish troops to regroup. When a battle takes turn for worse, Gimli and Aragorn heroically defend the bridge allowing soldiers manning the gatehouse to rebuild, and afterwards protect the king while he retreats to the keep. Then they convince him to lead one last sortie, while arranging for the women to flee through the mountain pass. Plenty of small-scale challenges in the midst of total chaos and what a battle to behold!
Best Answer
Kingmaker #5 War of the River Kings by Paizo has mass combat rules. Kingmaker #2 has domain rules for running a realm and building settlements.