So basically, L2 is just a special, mathematically significant point in space that moves around the sun in conjunction with the Earth.
If you consider only the sun's gravitational pull, then to orbit the sun at a given distance, you have to be at a specific angular speed. At that speed, your inertia offsets the sun's gravitational pull on you. Closer to the sun = faster, further = slower. If you are too fast for the distance you're at, you head away from the sun. Too slow, you get pulled closer.
So L2 is further than earth, so to be at L2 and remain in orbit around the sun at that distance, normally you'd have to orbit slower than the earth does. But it turns out that because of the extra gravitational pull of the earth, you can orbit the sun at L2 and do so at the same angular speed as the earth. Thus you can be at L2 and always be in the same relative position to the earth.
So, how does the halo orbit around L2 work? Because of conservation of angular momentum. Head closer to the sun, you speed up, gaining inertia. Now that inertia overcomes the sun's gravity, causing you to head further from the sun. But there you slow down again, and the sun's gravity wins out over your reduced inertia. So now you head closer, speeding up again, and so on. All the while, you're really just orbiting the sun. But meanwhile L2 is moving at a basically constant speed around the sun. So as you head closer to the sun and gain speed, you overtake L2. As you go further and lose speed, you fall behind it. So relative to L2, your path is basically elliptical with L2 in the middle.
Why don't they park the probe precisely at L2, instead of doing the halo orbit around L2? For one thing, L2 is in the earth's shadow. That's not good when you're powering your spacecraft with solar power. So you don't want to be right at L2.