Is it legal to rent out a house to pay the mortgage?

Yes