when someone calls me and asks for work-for-hire for his/her thesis; I don't know what to do
Just say NO.
I am struggling to earn money
There are plenty of ways to make money. Why do you want to do this? Writing a thesis is not an easy way to make money.
I think this way of earning money is not good
Okay. Then why do you want to do it?
However there are plenty of websites offering such services
There are plenty of websites offering good jobs such as helping poor disabled people. Why not join them?
Now, back to your main question,
Is it legal to write someone else's master's thesis as work-for-hire?
I am not a lawyer. I don't know the answer in your location. In my location, I do know that you will bear serious consequences if you write someone else's master's thesis and get caught . There are cases that people did this and their own degree would be revoked by the Ministry of Education.