How to ask for a recommendation letter if no professor knows me in person? I suffer from the following mental disorders, obsessive compulsive disorder, avoidant personality disorder and body dysmorphic disorder and at times I had depression and because of that I was unable to communicate and a lot of times attend the lectures so no professor knows me and they don't even answer my emails. I am very interested in having a master in mathematics and I need recommendation letters to apply, what should I do to get those? 

I somehow consider it rude to ask for it, especially when the professors don't know me, but I attempted to communicate with them through emails because I had no other choise, and never got an answer. If it was up to me, I would never ask for anything, but it is necessary.
Asking for a recommendation letter from a person who does not know you makes sense neither for you nor for a potential referee. The purpose of a reference letter is to let others know about your work habits, your motivation, your skills etc. A person who does not know you can not judge any of these things, thus even if you can convince a professor to write a letter about you it might not necessarily have a benefit for an application when it simply states that you have attended some courses. 
You could try to contact a professor in a field you feel motivation for and whose work you are interested in and ask about potential student projects, irrespective of courses or credits. This can:


Help get to know a professor personally
Help you figure out if you enjoy working in an academic environment
Get you a personal recommendation letter