Why do some clouds have flat tops?

A cloud can flatten when the air feeding it loses buoyancy and spreads sideways. In a tall thunderstorm, that often happens near the tropopause, the boundary between the lower atmosphere and the stratosphere. As the updraft fans out, it carries ice crystals outward and forms the broad top called an anvil. National Weather Service cloud guide.

Side view, schematic. The updraft builds a tower. Near the stable layer, cloudy air spreads horizontally.

Look for the tower and the spreading edge

Wide, flat top
Look for a high shelf extending sideways from a tall, billowing tower. That shelf is the anvil.
Bump above the shelf
A strong updraft can briefly rise beyond the anvil and form an overshooting top.
Flat underside
A level base on a puffy cloud marks where rising air cooled enough for droplets to form.

National Weather Service on overshooting tops · University of Wisconsin on cloud bases