Immigration is complicated, and you are thinking only of "legal" immigration. It is extremely common for people to ignore those laws. And a job is not always required, no.
You (generic you) don't need to really emigrate to a country to receive treatment, you could go with a tourist visa or visa free and get treated, then go back to the shitty country without universal healthcare where you live.
In my home country everyone has access to healthcare because it's a human right, so by law it doesn't matter what your immigration status is, you will get care. This includes cancer treatment, for free.