The timeline I’m looking for is anywhere from Roman times to the invention of gunpowder. After listening to a podcast about WWI, the narrator made it seem like the idea of entrenching oneself for protection was revolutionary in the way it was done, but that it had been done before. I’m curious if there were any major battles with swords and bows that utilized the idea of trenches for defensive positions.
Well my knowledge is mainly western european so I maybe unaware of uses elsewhere but I'll answer to the best of my knowledge. It wasn't particularly common in the medieval period to dig trenches to use them for cover from enemy fire. This is mainly just because given that arrows and crossbow bolts can usually be stopped by something like a wooden or wicker mantle which is especially a portable wall. This could be constructed out of range and moved forwards make it in some ways more useful than a trench for cover.
Trenches were however useful to stand not in but behind. Slowing down and disrupting the formation of an advancing enemy. For example at the battle of Loudoun hill Robert the Bruce dug in several lines of trench across the narrow road through the marshes to disrupt the English advance. Similarly trenches were commonly used by the attackers and defences during sieges. For the defenders a deep ditch dug at the base of a wall means that the attacker must take the time and risk to fill that in before they can bring any kind of large siege engine like a covered ram or siege tower up to the wall. Additionally it makes it much harder to conduct a surprise escalade, a rapid assault to take the walls with ladders. The attackers meanwhile would often dig ditches around their siege camps, this would protect them in the event the defenders sallied out of their fortifications to attack the camps, making it particularly hard for something like a quick cavalry attack to attack the workshops and burn any siege weapons or supplies they can get their hands on. Or taken to an extreme entirely enveloping a besieged position with a ring of ditches and walls such as the Roman siege of Jerusalem.
Using trenches as cover mostly began in the early modern period. As guns and cannons came to be more common and effective they could obviously punch through wooden mantlets and the like as such it became a common tactics to create approaches to the defences with trench works. Creating rings of trenches approaching the enemy defences, then as you got closer zig zagging trenches forwards towards the enemy walls. Then when you'd shelled a breach into the walls the infantry could use your trenches as cover to approach closer to the walls under cover and concealment before making the final assault.