The final voltage and total charge (conservation of charge) will be the same in both cases. As you rightly point out, there is a net energy loss which again is the same in either case. The problem is accounting for the energy loss in the first case where there is no resistor. In the second case the energy is lost as heat in the resistor. In the first case there is no dissipative resistance element - so where did that energy go? This an idealized situation, because in a practical circuit there will always be a means of dissipating energy in the wiring & component parasitic resistances.

As a conceptual exercise it is possible to account for the energy loss in the idealized situation with zero resistance, by allowing for the generation of an electromagnetic impulse wave propagating away from the circuit. But this is a rather (fanciful?) fancy way of explaining a situation that can't exist in practice. Or maybe not - one could search for an electromagnetic impulse wave near a practical circuit (with an intentionally low a resistance as possible) with a very high rate of change in current and somehow do an energy balance. Not an experiment I'm interested in however.