It has been tried in court [0], at least for discrimination against foreigners. However, nobody really want to take the landlord to court, and moreover, you don't want to live in the housing that the landlord specifically don't want you. So while everyone let it slips, it's actually illegal and there is an existing cases.
0: https://invest-online.jp/qanda/qanda-trouble-32-16916/ among other reference you can Google using the keyword in that article.