This does not mean that most roofs are in need of replacement, but rather that most are in need of some type of maintenance or repair. The problem here is that you often can't tell if the roof still leaks, unless it is inspected on a rainy day. Some stains are merely the residual effects of leaks that have been repaired. There is also the possibility that ceiling stains were caused by a former plumbing leak in the attic. Such problems can be pervasive, difficult to resolve, and sometimes very damaging to buildings.
Correction can be as simple as regrading the exterior grounds or adding roof gutters.
Unfortunately, major drainage improvements are often the only practical solutions, requiring costly ground water systems such as French drains designed by experts such as geotechnical engineers. Such problems may be the result of errors at the time of construction, but very often they are due to wiring that was added or altered by persons other than qualified electricians. If left unchecked, damage can become quite extensive. This statement is a red flag to most home inspectors, because no one could possibly know the entire building code, and the average person without professional involvement with the code is likely to know very little of it. Whenever an owner offers code assurance, I know that problems are likely to be found.