Lillie doesn't have to be that great of a Trainer if she is clever and capable of using her knowledge to turn the battle in her and the Sandshrew's favor, which I believe she is. It's possible the Sandshrew are losing against Tyranitar due to lack of strategy, rather than solely due to lack of strength. If Lillie is able to come up with a strategy that, say, takes advantage of Sandshrew's smaller size and the fact that the limited space of the cave might limit Tyranitar's mobility, then she may be able to gain the upper hand in the battle. As
@Darthlord7 said, Lillie doesn't have to dominate the battle or lose to justify her progress. The Tyranitar could retreat due to feeling overwhelmed by the large number of Sandshrew.