The total energy stored in a multi cell battery
You have it backwards.

When we observe what happens in the world, we notice interesting patterns that simplify things, and then we give them names.

For instance the product \$voltage\times width.of.battery\$ is uninteresting. It doesn't stay constant, it doesn't predict anything useful, it changes if we reconfigure the battery. So we can write it does as a sequence of terms, but it's not worth giving a name to.

On the other hand, \$voltage \times current \times time\$ is a very interesting quantity. We notice it's conserved under a re-arrangement of cells in a battery. Not only that, we find it's predictive of the amount of work a battery can do on a motor, where it's equal (in the limit of low losses) to the work the motor can do \$radians.turned \times torque\$ or \$height.lifted \times weight \times gravity\$.

It's so useful, we give it a special name, energy.

One of its properties is that if you have two cells that store the same energy, then the total is twice that of either cell. This remains the case whether you put the cells side by side, or end to end. It appears to obey the mathematical associative and commutative rules, things that make the concept so useful.

It can be justified post hoc by noting that the side by side arrangement (parallel) doubles the available current, and the end to end arrangement (series) doubles the available voltage, and that \$2IV\$ is the same product as \$I2V\$ (associative) or \$2VI\$ (commutative).

Please note that it's not the mathematics that control the way energy behaves. It's the fact that energy behaves this way that means we find it so useful to keep track of, more useful than the width.voltage product.