Would it be illegal/ against most university policies to ask a professor if you could teach their classes in exchange for food, shelter, and some access to their brain? A lot of professors don't like teaching or want to get their research done for tenure, so I feel it would be a win-win. It would be a good way to advance myself if i found a professor I wanted to work with.
There's no possibility whatsoever that this could work. To elaborate on Pete L. Clark's answer, here are some reasons:
The purpose of a teaching requirement is to have courses taught by the professor, not to have the professor arrange for some random person to teach instead. The administration and other faculty members would be exceedingly unhappy if they found out this was going on. Note that there are certain circumstances (called a course buyout) under which grant funding can be used to hire a replacement lecturer so the PI can focus on research, but this can only be done with university approval in advance. The replacement would be hired through the usual university hiring process.
I suppose this depends on the laws in your country, but I can't imagine labor laws permit hiring someone informally in exchange for food, shelter, and conversation. No university would tolerate this, since the legal risks are enormous.
Even if it were legal, it's obviously exploitation. Universities sometimes exploit people, but I've never heard of any university going so far as this.
What if you do a terrible job, or stop showing up, or assign bizarre grades, or harass the students, or try to blackmail the professor? No university is going to let a random person teach a course without at least some minimal screening or oversight, and no sane professor would accept an unknown stranger's offer to teach their course instead of them. Even if you just want to be an informal teaching assistant, there's still way too much potential for things to go wrong.
You could offer to give a guest lecture as a volunteer, but I doubt anyone would take you up on that offer unless they knew you well enough to be confident you'd do an acceptable job. Aside from one-off possibilities like this, you don't have any options outside of the regular process. You could try to become a graduate teaching assistant or adjunct (depending on your background), but working under the table is not an option.
Yes, in all parts of academic culture that I am familiar with, it would be either explicitly illegal (i.e., against the rules of the university) or prohibitively frowned upon for an instructor to subcontract courses in the way you're suggesting. Bottom line: virtually every faculty member would immediately and thoroughly turn down the request, and those that would not could get themselves in real trouble, up to and including being dismissed from a tenure-track -- or tenured -- position.
One could go into more detail about why this is such a non-starter as well as discuss certain acceptable academic practices which are somewhat related -- e.g. course buyouts, guest lectures, teaching assistants. Perhaps other answers will explore this.