If you want to GM some real trench warfare, I highly recommend, listening to Dan Carlin's "Blueprint for Armageddon" 5 parter on WWI, especially the descriptions of the Battle of Verdun. As a GM, you could LITERALLY lift language from his story telling to really bring the horror of the environment alive for your players. Also, if this world is mostly used to peace, the reality of trench warfare is going to be shocking, traumatic and horrifying to your entire world, from the nobility all the way down to the peasants. I would really lean into this in the story telling (also, perhaps some stuff like this happens).
As for tactics and fighting, there is a lot of media to draw inspiration from, as others have said. Things that occur to me are
- The battle of Ba Sing Se from Avatar: the Last Air Bender.
- Shadow and Bone (show is on Netflix, haven't read the books) has a world with late 1800s / early 1900s tech combined with magic users. At the end of season II there's some intense "squad of magic users vs squad of gun powder soldiers" events.
- Also, you can't go wrong with this kind of stuff.
As with real trench warfare, some of your major factors are going to be
- Artillery bombardment
- Air power
- Mechanized armor
Your fantasy equivalents of this stuff are going to be cool and endless (dragons are always an obvious one, but far from the only option). If a dragon is a fighter / bomber, a gryphon rider with a lance is an interceptor (but without any strafing ability). A number of big D&D monsters could play the role of mechanized armor (especially if someone's actually put armor on them). Regardless, the goal of artillery is going to be to bombard the battle field indirectly (and hopefully mostly hit the enemy and keep them pinned down and unable to advance safely), the goal of air is going to be to kill soldiers from above, the goal of anti-air is to stop the enemy from killing your soldiers from above and the goal of mechanized armor is to plow through bombardment and advance anyway. Just look the the Monster Manual and the spell descriptions and you'll see all kinds of stuff that could fill these roles in interesting ways.
Speaking of interesting roles, the excellent podcast Our Fake History has a 3 parter on the Seige of Vienna, which is a battle not really taught in American high school history that was REALLY cool and involved extensive use of sappers (you know, people who tunnel under defences). There are stories from the Siege of Vienna that squads of sappers tunnelling under the city defences ran into squads of sappers tunneling out into the battle field and the two sides would end up fighting with pick axes under ground. Sebastian (the podcaster) has some great speculation about what this kind of fight would be like. Do you hear them coming? What's it look like when they finally punch through into your tunnel? What's it like to be fighting in a low oxygen environment, lit by torches, while the room rocks from the blasting of other sapper parties and the ceiling could collapse on you in any minute?
Speaking of sappers. what would a bullette be like in sapper warfare? How about Earth and Water elementals? How about just fricken fighting some dwarves in those kinds of conditions?
Also thinking of trench warfare, I think of the German's use of gas in WWI. This leads me to think about potions / alchemy that could potentially be stuck into a cannon and shot out to explode and scatter amongst the enemy. Magical gasses / vapors could do much more than just kill the enemy. I'm envisioning gryohon riders dropping slowness potions tied to small charges, exploding in the air to rain down a slowness mist on an army right before the other army charges.
D&D bards could also have interesting affects on battles in a more technological or technomagical setting.