Targeting specific demographic using protected categories in other areas can be legal too.
As a pharmaceutical company you can target women, men, seniors for targeted medications. As a LGBTQ dating site you can target based on sexual orientation and cis/trans. It is not illegal. Housing and jobs (maybe something else) are covered by specific legislation.
The fact an LGBT dating site can choose ‘don’t show to heterosexual people (a waste of my ad spend)’ is one of the reasons their platform is so effective, especially compared to mass media like TV/magazines.
The analogous argument for knives would be "In the context of torture knives don't have any legal uses. (So knife sellers need to put safe guards in preventing their knives from torturing people)".
In the context of housing ads (or employment) these tools DO NOT have legal uses.
Thus they are illegal.