Here's a bit of speculation.
Rewatching some of the league episodes, I think there's an unusual amount of time spent focusing on James' new mecha. He's styling it as the most powerful one he's ever built, and with the loads of money Team Rocket has been making from their donut stand, there is foundation for an insanely powerful robot.
I don't actually think it'll be used against Ash & Pikachu. The outstanding storylines that need to be finished before SM ends:
-Mohn/Magearna
-Snowy evolution
-Pikachu & Tapu Koko
-Team Rocket accomplishments
-Ultra Beast apocalypse/Dia
-Graduation & goodbyes
In Kalos, Ash was sort of the hero of the Team Flare arc even though he and Greninja were closer to damsels-in-distress. I don't think Ash will play that role here since Alola has been very big on the community effort - look at how Ultra Necrozma was resolved, literally the entire region in two different dimensions worked together to resurrect him.
Wouldn't it be brilliant if Team Rocket's Ulta Mecha, then, is the hero who saves Alola from the terror of Guzzlord? That would neatly solve the UB apocalypse while also giving TR a tangible accomplishment. During the UB apocalypse in Dia's world, Z-Power stopped working right before Guzzlord appeared, removing the only way of permanently defeating it. If the poisoned land was the cause of the Tapus losing power (Fairies weak to Poison?), I can see the Alolans working together to clean stuff up while Team Rocket battles the UBs.