Let's also not forget that we have no idea what psychological abuse Lillie had gone through at the hands of Lusamine. By her actions I wouldn't be surprised if she had an inferiority complex, her mother caring very little for what she wanted and preferring to focus on the Ultra Beasts. Lusamine probably multiple times told Lillie she might not be worthy of her love when/if she acted up or against what Lusamine wanted. Lusamine is a terrible person, but she's still is Lillie's mother and being rejected and abandoned by your own mother, especially one you had fond memories of growing up and it's only recent times she started acting harshly, can be very traumatic. Especially for someone who was as sheltered as Lillie.
Why doesn't Lillie become a trainer during the the game? Well let's remember Lillie's upbringing was in the Aether Foundation and their conservation ideology. She doesn't like Pokemon getting hurt, and Pokemon get hurt when battling. But her interactions with the player and Hau showed her that trainers wouldn't have their Pokemon battle until they would seriously hurt themselves as she was probably raise to imagine, but rather trainer battles is recreational for both Pokemon and trainer and meant to strengthen the bond between them, between people and Pokemon. This can be shown with Lillie's and Nebby's relationship. Lillie never wanted Nebby to do anything, worried it would get hurt and keeping it hidden in her bag. But Nebby kept escaping, and it was only until recently did she decide to take Nebby to the Tapu's ruins. Lillie was protecting Nebby, but she wasn't thinking what Nebby wanted thus why it kept disobeying her. Her finally helping Nebby do what it wanted, while also protecting it, allowed it to become the Legendary Pokemon. This and witnessing our Island Challenge showed her what a trainer was which let her decide to start her own journey.
Yes, Lillie had Mary Sue traits, but I feel that's pulling from another trope she fully represents:
the Woobie. You feel sorry for her at first due to her
shrinking violet personality but then for her past. She's kind and polite which explains why the majority of people like/are friendly toward her. But she is missing some Mary Sue traits. She's not perfect, we're told and shown she her skills are limited though she tries her best. And while she has importance she's unable to do anything without help from others, even when she becomes her "Z Form" she needs Gladion to give her the Sun/Moon Flute and the player to accompany her. Now I'm not saying you should or shouldn't like her, there is reasons for both (it's as if she's a well-rounded characters...), but she's not a Mary Sue. Compare Lillie to an actual Mary Sue-ish character, Zinnia, and you'll see how she differs from a Mary Sue.