Were early cell batteries tube shaped, so they fitted into flashlights? Did someone say, “Aha, I can make a torch with this”. We think the relationship between form and function was probably iterative, and battery and flashlight designers worked together. Nonetheless, batteries have different shapes that serve their purposes remarkably well.
Some of the Reasons Why Batteries Have Different Shapes

Take automobile lead-acid batteries, for example. If they were cylindrical and not rectangular, they might roll around if not secure. If they were lightweight, they would not sit as firmly in their cradles either.
The first lead-acid battery by Gaston Planté was actually tubular. However, this proved impractical to mass produce in a non-mechanized 1881. That was when Camille Faure produced the first rectangular commercial version and it stayed with us ever since.
Hence, there is a third leg to the form-versus-function debate, namely what is practical to do. While batteries have different shapes nowadays, there are still masses of cylindrical cell types. This is because they are mechanically stable, cheap, and easy to make. We can’t see these disappearing anytime soon since they are so user friendly too.
How Electronics Changed the Battery World

Electronic engineering introduced the possibility of small-sizing things. Bulky portable radios gave way to Sony Walkmen with headphones. That was just the beginning.
It would be hard to imagine hearing aids, car keys, medical implants, and watches without button cells of various sizes. In this case, the function demanded it and form came to the party.
How Tablets and Smartphones Dictate Shape
Prismatic flat cells are the battery industry’s response to demand for thin and flat batteries for tablets and smartphones. These have different shapes according to device design. While prismatic cells are strictly rectangular, pouch cells that followed can come in any shape we want. Thus the answer to why batteries have different shapes is, because that’s what we, the consumer demand.
Related
How to Recycle Different types of Batteries
Preview Image: Charging Smartphone Battery