This may be due to a misconfigured server or application.
A source code disclosure may allow an attacker to have better understandings of the inner workings of the application. This knowledge can be leveraged to expand the attack surface.
A source code leak may happen in different ways and thus there is not a generic solution. For example the server may force the download of source files, which could not be interpreted because of a misconfiguration.