Your friend can apply for asylum here. As long as your friend still has a valid residence permit and applies for asylum before it expires, then they are not obliged to live in a special refugee reception centre. For people who have residence permits and apply for asylum, the rules around accommodation are different to a person who does not have a residence permit. However, if they apply for asylum and are not able to pay for their own housing, then they will be housed by the social office (Sozialamt). This would likely mean the person would be housed in a refugee centre (Gemeinschaftsunterkunft). If your friend is in a particularly vulnerable situation (e.g. for health reasons), they can request adequate housing, for example in an apartment offered by the Sozialamt. Your friend can continue studying if they apply for asylum.
Regarding health issues, I presume while studying your friend has health insurance and so has access to the German health system. If they apply for asylum, their healthcare will be covered by the Sozialamt. If they have issues with their health insurance, they can contact one of a number of organisations which assist people in such situations. Here is an example of one such office in Berlin:
Even if your friend has access to the regular German healthcare system, it is possible they would prefer to receive mental healthcare treatment in their own language and sensitive to their needs. For this they can contact one of the PSZ (psychosocial centres) which are specially for refugees. Here is a list of such organisations:
I advise your friend to make contact with an organisation working in this area before making an asylum application. Here is the website in English of ‘Queer Refugees Deutschland’. They have lots of information and also provide contact details of associated organisations throughout Germany:
If you or your friend have any other questions, do not hesitate to contact us.