Sometimes it seems that a landlord has a “right” to evict you. He has given you a proper notice to terminate a month-to-month tenancy, or a fixed-term lease has expired. If you don’t leave, he will sue to evict, and your position seems hopeless. But even where it seems that his right to evict is absolute, the courts may refuse to help him if the reason underlying his desire to evict is to “retaliate” against you for your exercise of some legal right.
When getting evicted, suppose you have a month-to-month tenancy and the landlord refuses to fix a leaking roof. You complain to the city’s housing inspection department, and the landlord learns of your complaint. Not wanting a troublemaker like you around anymore, he serves you with a notice terminating your tenancy. If you fail to leave and he sues to evict, you may raise the defense of “retaliatory eviction”.
If you prove the landlord’s reason (which might not be easy), the court will refuse to evict you. Getting evicted in this situation would discourage other tenants from reporting code violations. Because code enforcement agencies depend (in part) on tenant complaints, and one of the basic purposes of the code enforcement program would be undermined. The court will refuse to help the landlord undermine the efforts of another government agency.