In the original draft, the machines were using human brains as a networked computer. The simulation is necessary because sensory input and simulation is how human brains compute - it's for the humans, not the machines. Unfortunately the studios thought that was too complicated and we wound up with "lol batteries" and none of it makes any sense.
Also, I mean, because without that there wouldn't be a movie.
Yeah - the whole point of the simulation was to keep the brains engaged. A distraction if you will, from the fact that they aren't actually doing anything.
WHY would a machine need a simulation at all?