Are professors obligated to accept supervisory role? If not, how does it work? Firstly, I am not specifically talking about PhD supervision. I think that's less relevant for my question since a PhD supervision is usually a mutually beneficial arrangement, as the professor gains a PhD student to help them with related research. 

My focus is more on supervision of bachelor and masters theses. In these, there is less benefit to the professor to act in a supervisory role. 

So with that in mind, if a student contacts a professor because they need a supervisor for their bachelor or thesis project (something which is a requirement in order to get the degree), is the supervisor obligated to accept this role? 

I don't think the answer is yes, since people usually say that if you want to get a supervisor, you should ask your professior if he/she wants to. So the words imply that the professor has a choice and could turn you down.

And so if the answer is indeed no, how does the system then work? What happens if nobody wants to supervise one particular student? Is that student then just screwed?
The exact answer to this is likely to vary from one university to the next, depending on local rules and terms of employment. In general, the position is likely to be: professors are not required to agree to a student's request for supervision. However, it is generally advisable/mandatory for professors to accede to 'requests' that come from higher up in the management hierarchy.

If students are required to complete a supervised project as part of a course, then it is the university's responsibility to ensure that an appropriate supervisor is made available. If a student reported that they cannot find a willing supervisor, this would likely result in management applying increasing amounts of pressure and/or incentives until someone agreed. However, in such circumstances, the student is likely to be left with Hobson's choice - the project offered may not be a close match to the student's preferences.