Here's a more in-depth explanation:

Imagine this box is the room being described. The longest straight line we can have within the room is from the bottom corner on one side to the top corning on the opposite side (line d pictured).
Now all we have to do is find the length of line d. We do this by constructing two different triangles. The first triangle will use the length and width of the room to find the length of a diagonal. In other words, we're looking for the line that goes from one floor corner to the furthest opposite floor corner (which is right below the ceiling corner we're using for line D).
The diagonal is the hypotenuse of a right triangle involving the length and width, so using the Pythagorean Theorem we know that A^2 + B^2 = C^2. In this case:
15^2 + 16^2 = diagonal^2
225+256=481 so the diagonal is sqrt(481)
Now that we have the diagonal we can use sqrt(481) and the height of the room (12) to create a second right triangle with line D as the hypotenuse. The first triangle was 2D and all 3 points lay on the floor, the second triangle is standing up on edge with one vertex at the ceiling and the other two on the floor. The hypotenuse is the line running from that ceiling corner to the opposite floor corner. Using the same formula:
sqrt(481)^2 + 12^ = hypotenuse^2
481+144 =625
sqrt(625) = 25
so using this method we see that the longest straight line we can draw inside this room is 25 feet long
hope this helps!