We have a geometric construction as shown in the image below. We can see that
Or, equivalently
The triangle formed by r,h and L/2 is right, because the opposite side of the square is tangent to the circle at its midpoint. This means we can use Pythagoras's theorem: