Maybe I cracked the mistery.
Remember that Trost was blocked off so the Corps had to take that huge detour? Annie must have sneaked off to Trost and transformed out.
She must have borrowed a horse to get there without rising too many suspiction on herself or left during the night to get in position before the Corps left then waited for them to get close.
However we have to keep in mind that she was also supposed to get back to Marley in case of success so she may have got sloppy in her attept at hiding her identity, which while the Military Police passed over her absence cause they are all lazy kitties, it ended with her getting easily discovered by Armin.
Her original plan was probably to lead the Titans as a distration for Squad Levi while she got Eren.
This Titan army might have been ordered by Zeke himself, who might have made the whole plan, or by Annie we don't know for sure.
However the original plan failed cause Erwin is a smartass so she had to improvise and ended with Petra hugging trees and yada yada.
Now how did Annie get back to the Walls? fighting Levi again was out of the question cause by the time she was all healed up they were already gone and she couldn't catch up with them cause she was exhausted so her only option was to head back in her Titan form then climb the Wall with Marco's gear or something.
Now I got to enact the Attack on the WC cause I am stupid and didn't want to leave my desk before finishing this post.