If you own the property, it is legal to rent it out for as long as you own it.
That said, it would be unethical, (at least) to rent it out, when you know that your tenants will be evicted soon:
I can see a senario where you could get sued for putting them in that position.
And what is going to happen with the rent money they pay, while you are not paying your mortgage?
Could someone view that as fraud?