From the same reason people don't fall off their bikes when riding, and why dreidels and gyroscopes don't fall off. It is due to the conservation of angular momentum.
First, note that the solar system is not entirely flat; Pluto's orbit, e.g., is inclined about 17 degrees relative to the plane of the solar system. Still, most of the solar system (as well as bigger objects, such as galaxies) is exceedingly flat.
The reason for that lies in one of the most important discoveries of classical physics: that of conservation laws. As it turns out, in any isolated physical system, there are several quantities which are conserved, although the system itself evolves; namely, the different ingredients (e.g., particles) that compose the system can change their properties (velocity, etc.), but several "global" properties of the system are not changed. Such a conserved quantity is, for example, the system's energy; another example is its linear momentum, and a third quantity - one that is most relevant for answering this question, is angular momentum, or global "spin". As a side, these conservation laws are believed to represent fundamental laws of nature.
Angular momentum is the rotational analogue of linear momentum. It represents, in some basic sense, global conservation of rotational properties, or "spin". So, how is it related to the shape of the solar system (as well as other big bodies, such as galaxies, etc.)?
The solar system was created when a big cloud of gas collapsed due to the force of gravity, forming the sun as well as the planets surrounding it. Initially, this (3-dimention) cloud was composed of gas particles that collided with each other. In each collision, each particle changed its velocity, etc. (in some collisions the particles got stuck together); while the trajectory of each particle is impossible to track, the global rotation was conserved, not affected by the collisions. This means that even if all the particles are stick together into one big object, it would still rotate on the same plane as defined by summing up the rotations of all the initial gas molecules. Of course, initially the particles did not move just on that plane; but the motion up and down to that plane of the different molecules cancel each other. As time elapsed and more and more particles collided, the cancellation of the up/down motion became more and more pronounced, and particles accumulated on the rotation plane; but the global rotation itself could not be canceled without external interference. Thus, with time, the cloud lost its original 3-d shape, and the matter concentrated in the 2-d rotational plane composing of our solar system. A similar mechanism holds for other objects, such as galaxies.