IMO, Lili wanted to be on the other side as both a spy/a diplomatic force to try to keep Imu in line.
Now that's it's proven by Lili's own words she was friends with Imu, it makes a lot of sense that Lili would stay close to Imu during the Void to try to keep his worst impulses in check, kinda like the Gorosei try to do in the modern era.
If Imu was close friends with Lili, and she was a beloved Queen worldwide, it makes a lot of sense, if Lili was like Vivi, for Lili to stay by Imu's side to try to stop him from furthering the war.
Lili was playing both sides because she honestly loved both sides, and Imu, due to his love for Lili, has probably never been able to fully blame her for her betrayal, instead blaming Joy Boy for it. This is why Imu ABSOLUTELY crashes out over Cobra's letter:
Imu can no longer lie to himself and blame Joy Boy and Davy Jones for everything. Lili's Letter Cobra read directly proved Lili betrayed Imu, and it just BROKE him when he realized.
The moment Cobra states Lili was a "D", Imu just CRASHES out.
For 800 years, IMO, Imu was making excuses to absolve Lili. In this moment, he had to fully accept her betrayal.