Why aren't galaxies distributed evenly in space, but instead form those sponge-like structures, with huge voids between filaments?

Void formation is due to baryon acoustic oscillations. These can be thought of as fluctuations in the dense matter in the early stages of the universe; they became anisotropies, which can be seen in the cosmic microwave background. The fluctuations grew, until they hit the 150 Mpc scale, which correlates nicely to the sizes of voids in the universe today.

There's an interesting section (4.2) in this paper by Robert Brandenberger, which gives a mathematical treatment of how fluctuations of *all* kinds grew in the early universe. There is a better version of the explanation in Zeldovich (1972), which in fact puts forth the theory. The number density (if you'll pardon the pun) is lesser in that latter, but the former has a good overview, as it is meant to be a broad summary.

The simple explanation is that tiny fluctuations grew over time to become enormous structures.

You might like to watch this short movie from one of the authorities on this subject: https://www.youtube.com/watch?v=wI12X2zczqI

The movie starts by answering the question "what is the cosmic web and what does it look like?". Simulations can reproduce such structures, but they do not explain "why" they look the way they do. The clue lies in the geometric appearance of the structures: The voids resemble the elements of a Voronoi tessellation in which the walls of the Voronoi polyhedra intersect in lines that are identified with the filaments. We need to understand the dynamics that generated this pattern.

At around 2:30 the movie addresses the issue of why it looks the way it does using a simple ballistic model for the motion of a set of discrete particles that represent a random density field (the Zel'dovich model). The filaments are there but too fuzzy. So at ~3:00 it generalizes this so as to achieve greater realism by making the particles sticky. This is the "adhesion model", which is governed by the Burgers-Hopf equation, which is easily solved by geometric means. There is no gravity in this - it's ballistics acting on density field generated by a Gaussian Random process with a known covariance function (or power spectrum).

The adhesion model is a remarkable representation of the structure. It shows how nothing "special" is required to generate the pattern of the cosmic web. That's the "how".

The "why does the structure look like it does?" is a little more complex: this is the question of emergent geometry which is understood in terms of the technical language of the Lagrangian description of the flow. But the graphics is pretty and quite didactic, so worth a look. This happens after around 5:30.

The movie compares appearance of the flow simultaneously in both Lagrangian and Eulerian space. In the Lagrangian picture the particles have fixed coordinates,

A short descriptive article goes with the movie: http://arxiv.org/pdf/1205.1669v1.pdf and a short explanatin of the Lagrangiuan view is at http://arxiv.org/pdf/1211.5385v1.pdf This is part of the thesis work of Johan Hidding from the Kapteyn Instutue in Groningen (supevisor Rien van de Weygaert - the father of the cosmic web according to Richard Bond). A full presentation of the nature of the singularities in terms of Morse Theory is at http://arxiv.org/pdf/1311.7134v1.pdf and there are several other papers pending.

The baryonic acoustic oscillations (BAO) have a present-day scale $sim 100 h^{-1}$ Mpc. This has little or nothing to do with the appearance of voids, which appear predominantly on scales of $sim 20h^{-1}$ Mpc. and below. The BAO scale is only detected in the galaxy distribution by correlation analysis and does not manifest itself by mere visual inspection, unlike the voids, filaments and clusters that dominate the appearance of the cosmic web. If anything, the voids scales are determined by the velocity field power spectrum, which is to be expected in light of the way the Zel'dovich approximation works (as explained in the movie I referred to).

I would have added this as a comment to the post except that I have insufficient reputation and so this is the only way I can make the point. Apologies are offered if they are in order.