For example, if in the code someone use the following:
response.SC_REQUEST_TIMEOUT;
1- does it invalidate the session?
Setting the status code does not affect the session, you need to manually invalidate the session, or it has been already invalidated. The error code is just be used to tell the browser or user the problem encountered.
2- is anyone actually sets these codes in real world?
If you wanna use the default error page by the browser, you need to set it. If you have customerized error messages, you might no need it.