Legality of selling fan art

I go to several anime conventions a year, and this is something that is sort of controversial. I am referring to fans producing their own posters and merchandise with copyrighted characters on them and selling them at the event. Some conventions embrace this, and others don’t allow it at all. One that I go to is very anti-bootleg, and they allow this to some extent, but are very strict about it. I remember hearing there that fan art can be considered to be illegal.
This is all from a US perspective. I am not a seller, and not looking for advice. What does the law say about fan produced art?
I know Square Enix has sent lawyers to stop people from selling copies of swords from their games.

From my very limited perspective (public librarian who researched it in order to have a library-based mini-convention) the law does not specifically address fan art at all, which is why it is murky and controversial.

From a purely technical standpoint, many business entities (but not all) own exclusive rights to the depictions of their characters, full-stop, and therefore strictly legally speaking, ANY fan work depicting them is in fact totally illegal.

However, most companies are clever enough to notice that the ones making these fan works are their most rabid fans, and that in some cases, the creation of fan works drives interest in the original IP, to the benefit of the company - so despite their legal rights, they choose to ignore minor infringement.

The obvious downside here is that they can choose to also stop ignoring it at any time, (especially because certain sorts of properties require proof from the company that they are defending their continued rights in the product/property) which makes many fan artists (not rich, not connected) quite nervous. Things like adding fan profit to the mix makes it more likely to get attention (non-profit fan work (including cosplay among other things) has been somewhat cleared under Fair Use to a collective sigh of relief) and using characters in ways that stridently contrast with the spirit or intent of the original IP seems to be another that often triggers a response. Some creators or companies are simply controlling and will squelch anything and everything out of a strong sense of their ownership being infringed upon.

So - most likely it will remain a grey area. There’s no benefit to the companies to making fan work of their IPs any more explicitly legal because it makes their range of options narrower, and frankly exposes them to more risk in the way random people can mess with their IP content. And there are very few, if any, fans with the necessary clout to get such laws passed in the fan’s favor.