Short Version: When the resistance in the above circuit is zero, the system will never attain equilibrium.
Long Version:
Any time you want to understand what happens with a zero resistance you need to start with a small but non-zero resistance and see what happens in the limit of $R \to 0$.
by John Rennie sir in chat.
When a capacitor of capacitance $C$ is given a charge $Q$, and at time $t=0$, it is connected to an uncharged capacitor of equal capacitance through a resistance $R$, the charge on the second capacitor as a function of time is given by the following equation:
$$Q(t)=\frac Q 2 (1-e^{-2t/RC})$$
When the resistance in the circuit is non-zero, it takes some time before the charges in the two identical capacitors equalise. The charge on the two capacitors after a long time will be equal to $Q/2$. If you calculate the energy stored in the electric field in the capacitors before and after the connections are made, you could clearly see some energy loss (and this is what the example problem in the question is about).
When there is some resistance in the circuit, the energy is lost due as heat developed in the resistors. But your question is how (and why) is the energy lost when there is zero resistance in the circuit? It turns out that when you analyse the system when $R\to0$ using the equation mentioned earlier, the time constant ($RC$) decreases with decrease in $R$. Or in other words, the time required to attain equilibrium reduces.
But when you put $R=0$, we get an invalid equation. Or we can imagine the system to never attain equilibrium. Usually when you have non-zero resistance, the energy lost due to thermal energy damps the oscillations of charges in the capacitors. You can imagine this to be similar to that of a pendulum which stops oscillating after some time due to energy lost to the surroundings. However, when no energy is lost to the surroundings, the pendulum keeps on oscillating. In a similar way, when there is no resistance in the circuit in your example, the system never attains equilibrium. Charges get continuously transferred back and forth between the two capacitors somewhat similar to how energy is interchanged between an inductor and a capacitor in an LC oscillation (as pointed out by Keith McClary).