Imagine observing a lightning bolt strike the ground. The bolt travels through air almost instantly and emits sound in every direction throughout its path. First you will hear the sound waves emitted from the point that it touches the ground, because that is the closest. Then you will hear the sound waves from 1 cm off the ground, 2 cm, 3 cm and so on all the way up to the lightning bolt's point of origin in the sky. By measuring the duration of the noise you can tell the length of the lightning bolt (assuming it's perpendicular to the ground).
It's basic properties of propagation of light and sound.
In practice, the duration of thunder from a given lightning bolt might be affected by echos and other phenomena, though you could probably get at least a rough estimate of bolt length by the duration of thunder.
The largest lightning bolts ever measured are hundreds of kilometers long. The longest I'm aware of was over 760 km long (477 mi), measured in February of this year:
That probably roared for a while, though attentuation of sound would likely occur within 16--32 km (10--20 mi), or a minute or two. Otherwise, it would take nearly 40 minutes for sound to propagate from one end of the strike to the other.