If an owner seeks to displace a tenant or lessee from accommodations withdrawn from rent or lease pursuant to this chapter by an unlawful detainer proceeding, the tenant or lessee may appear and answer or demur pursuant to Section 1170 of the Code of Civil Procedure and may assert by way of defense that the owner has not complied with the applicable provisions of this chapter, or statutes, ordinances, or regulations of public entities adopted to implement this chapter, as authorized by this chapter.