A thermal does not continue upwards beyond the top of any cloud it might form, but it actually becomes stronger when a cloud does form, and can rise to the tropopause, creating towering thunderheads and many other weather phenomena.
As the air in a thermal rises, it expands, maintaining the same pressure as the surrounding atmosphere (which decreases with altitude).
this expansion against the pressure of the surrounding atmosphere does work, just as a gas expanding against a piston in a cylinder does work. The energy for this comes from the thermal energy of the air in the thermal, causing it to cool down.
Because a thermal is large and air is a poor conductor of heat, this occurs with only an insignificant flow of heat between the thermal and the surrounding air (and the mixing at the boundary is similarly small in relation to the mass of the thermal). Consequently, the change in temperature of a thermal with change in altitude can be calculated on the assumption that it is entirely due to the work done by expansion, and, for dry air, that turns out to be 9.8 degrees C per 1000 meters. This is known as the dry adiabatic lapse rate ('adiabatic' referring to physical processes that occur without heat or matter flow.)
As the rising dry air cools, it does not lose any moisture, so its relative humidity increases. When that reaches 100%, the air has become saturated, and further cooling will cause some of the moisture to condense, leading to the formation of a cloud. The moisture does not all condense at once; the amount that condenses is the excess over 100% humidity at the new, lower, temperature.
The condensation of this moisture releases the latent heat of condensation of this moisture, which compensates for some of the heat loss due to the work being done by the expanding thermal. Consequently, the lapse rate (rate of cooling with altitude) decreases within the cloud. The contribution of this condensation is dependent on the temperature (there is not much moisture to condense in cold air, even when saturated), but Wikipedia gives 5 degrees C / 1000 meters as a typical figure for the moist adiabatic lapse rate. Note that this is approximately half the dry lapse rate.
A thermal will continue to rise so long as it is warmer than the surrounding air (though there may also be an effect from the lower density of water vapor if the humidity of the thermal and surrounding air are significantly different.) Let's consider a dry/clear thermal in dry/clear air: as the thermal starts off only slightly warmer than the surrounding air and cools at the dry adiabatic lapse rate, this means that for it to rise to any significant height, the surrounding air must have a lapse rate (rate of cooling with altitude) very close to the dry adiabatic lapse rate (it cannot be higher, because that would be unstable: convection would spontaneously form and continue until this turning-over and mixing of the atmosphere reduces the lapse rate to the adiabatic.) (For completeness, I will just note that very close to the ground, the lapse rate can be super-adiabatic.)
A sufficiently-deep inversion layer (one where the air temperature increases with altitude), or one simply with a lapse rate below the dry adiabatic, will cause a thermal to stop rising (if it has not begun to condense) and no cloud will form. If, however, the thermal reaches the condensation level, then a cloud will begin to form, and its lapse rate will decrease to the moist adiabatic lapse rate for its temperature. If the temperature of the surrounding air continues to fall with altitude at the dry adiabatic rate, then the temperature difference between the thermal and the surrounding air will actually increase with altitude. This increases the thermal's buoyancy, making its lift stronger - an effect well-known to glider pilots - and requiring a larger inversion (or layer with a lapse rate less than the moist adiabatic) to stop it.
This is the primary mechanism by which the condensation of moisture drives thunderstorms, hurricanes and other non-orographic rainfall. A summer's day may start with an inversion stopping convection at a few thousand meters, but as the day warms up and thermals carry the heat upwards, the inversion is eroded by heating from below. By afternoon, the thermals may break through the inversion, particularly if condensation begins. With condensation powering the convection, it may go all the way to the tropopause and spread out under the stratosphere (which is a giant inversion), producing the anvil-head cumulonimbus cloud of a pop-up thunderstorm.
If the atmosphere's lapse rate is between the dry and wet lapse rates, it is only conditionally stable: if a mass of this air is lifted to the point where condensation occurs, it will now have a lapse rate less than that of the surrounding air, and will continue to rise, driven by the condensation of its moisture. One way this initial uplift can be caused is by the cold outflow of a thunderstorm pushing along the ground. This is the mechanism by which a derecho can travel hundreds of miles through a conditionally-stable airmass.