How can computer memory remember after the computer runs out of battery?
There’s permanent storage that doesn’t need any power and lasts forever.
Your computer likely has a tiny battery for important things like clock time which should last for a very long time.
Your computer probably has code that dumps all memory contents to permanent storage just before the battery runs out and reads it back when there is enough battery life.