Magnetic field lines curve because magnetic fields have finite curl and zero divergence. To visualize what those terms mean, imagine you have a pool of water which is moving around in some way. At each point of space in the pool, the water current has a direction and rate of flow.
The curl can be thought of as how much the current "swirls" around the pool. A pool where the water flows around in circles has lots of curl.
The divergence is how much the water diverges (or converges) towards a single point. If you put a drain in the middle of the pool so that the water flows straight in, you have high divergence because all the water is converging towards the middle.
When a toilet flushes, you have both divergence and curl. The water flows around in what is essentially an inward spiral, so it is both swirling and converging.
A magnetic field has curl but no divergence, so the field lines can "swirl" around in circles (or ovals or what have you), but cannot converge or diverge. The field lines thus cannot "spiral" inwards or outwards, a field line must go out, circle around due to curl, and end up back where it started. If it didn't end up back where it started it would have divergence, and it doesn't.
The reason we know that magnetic fields have curl but no divergence is from Maxwell's equations. Roughly speaking, Maxwell's equations tied together a bunch of experimentally derived laws that other people had come up with in a cohesive fashion, and extended those connections to make a few more novel statements as well.
Hope this helps you