All of the planets orbit in basically the same plane because the Sun and the planets were originally condensed out of a spinning nebula of gas and dust. As it collapsed, the cloud flattened into a disk with the Sun at the center and the planets formed farther out.

But why did all the dust (and gas, the vast majority of the mass) end up in a plane? To get a little technical, if you start with a rotating irregular blob, which is the usual case, then collisions between the particles tend to average out the motions of the particles. Thus the motions perpendicular to the spin equator get zeroed out and the motions parallel to it get averaged to the general rotation rate.