Clouds form because the air cools enough to condense the water out of them into droplets. So if the clouds end at a certain altitude, it means that enough moisture in the air has condensed out such that the amount remaining is low enough to stay gaseous.
Sometimes this happens at low altitudes, sometimes (such as thunderstorms), it happens at really high altitudes. In the case of thunderstorms, the speed of the rising air helps carry the moisture higher before it condenses, but even then you get the flat tops of the anvil clouds when it gets high enough to condense out the moisture.
Now, for why two layers may sometimes form. If you look at the International Standard Atmosphere:
and you look at the red line indicating temperature, you can see that it decreases up to about 11km. As that happens, the water condenses and may form the first layer of clouds. The remaining air may still have some water vapor in it, but it will be below 100% relative humidity.
Above this, for the next 10km, the temperature is actually constant. This means it isn't cooling enough to condense any more water. The pressure is decreasing, so it is possible the amount of water that can be supported will drop. Above 20km, the air actually gets warmer again, although not many clouds will be that high up. That second, higher layer of thin ice crystals you sometimes see in the sky is separated from the lower layer because the pressure has to decrease enough to condense it out, as opposed to cooling.