The problem is that these specific errors occur before ASP.NET can load things, and your Internal Server Error page is the .aspx page for which ASP.NET needs to be loaded.
The easiest option is to make your page 500 HTML pages, but that means you cannot make a simple error log, etc. from there.
This may still not help the web.config script, as if IIS could not process the web.config file, there is no guarantee that it will read your error section.
Another option is to tell IIS to serve a static html page with 500 errors.
Finally, you can try to catch errors in the Application_Error event in the web.config file - this will at least allow you to handle the error even if the page you are trying to display cannot load.
Edit to add
If you are running IIS 7 in integrated mode, you need to do one more thing if you set the response code on the error page to 500:
Response.TrySkipIisCustomErrors = true;
However, note that the following conditions will stop the user from displaying 500 error pages, resulting in YSOD:
- Errors in the web.config file or some handlers in the web.config file that run before the rest of the pipeline (i.e. the main part of the original response)
- Errors on the error page.
source share