Let us begin with the Maxwell's equations for electrostatics and magnetostatics.
For electrostatics:
$$\nabla\cdot \mathbf{E}=\frac{\rho}{\epsilon_0} \\ \nabla\times \mathbf{E}=0 $$
For magnetostatics:
$$\nabla\cdot \mathbf{B}=0 \\ \nabla\times \mathbf{B}=\frac{\mathbf{J}}{c^2\epsilon_0}$$
The equation $\nabla\cdot \mathbf{B}=0$ in magnetostatics says that the divergence of the magnetic field is always zero. Comparing this with the analogous equation $\nabla\cdot \mathbf{E}=\dfrac{\rho}{\epsilon_0}$ in electrostatics, we can conclude that there are no magnetic charges. This implies that the magnetic field lines neither starts nor ends (for exceptions, see this paper). Then what is the origin of the magnetic field?
Magnetic fields are always associated with electric currents, and the equation $\nabla\times \mathbf{B}=\dfrac{\mathbf{J}}{c^2\epsilon_0}$ says that the curl is proportional to the electric current density. So the magnetic field lines in seldom cases form closed loops around the current vectors (for the general case, see this post).
Now the question is: Why don't electric field lines form closed loops?
At first sight, one might think that electric field lines also form closed loops when $\rho=0$. But this is not the case. To understand this, look at the equation $\nabla\times \mathbf{E}=0$ which says that the curl of electric field is always zero. This simply means that electric field lines can never form closed loops. This fact is closely related to conservative nature of the electrostatic field.