It's legal if published with universal free access, because WotC permits it.
Law as written generally requires the original copyright holder's permission to publish a story around copyrighted characters. Fair use mostly applies to reviews and other indirect use, rather than straight adaptation; it likely wouldn't apply here, but it doesn't need to. D&D's rights holder, WotC, has provided a broad license to create and publish D&D-based content, extended to everyone.
So: you can create and publish stories, comics, or anything else, as long as you are publishing them for free. "Free" is defined here as not requiring money or other conditions for access.
You are allowed to publish it on any public website, which doesn't require a subscription or payment, build an audience, benefit from ad revenue and sponsorships, produce and sell merchandise.
This license does include other conditions:
- Share-alike: if you rely on this license, you also permit everyone else to share your work or build upon it.
- Indemnity clause (they rarely come in play, but are very non-obvious).
- Revocability: WotC has the right to change this license, or to revoke it case-by-case, e.g. if they think the content will hurt them.
- No trademark license: you can't brand your publications or merchandise with official D&D logos.
This license is similar to what other franchises provide for fan works, when they do so, and leans on the permissive side. Most things short of a paper book or subscription-only content are allowed.
What's not allowed is any paywall or login-wall, including sitewide subscriptions and free subscriptions. You need to make sure the sites you publish on are open to read for anyone, without logging in. Paid access options on Patreon, Tapas or Webcomics are not allowed by this license.
For creating commercial D&D content, one would want to see the Systems Reference Document, dual-licensed under the extremely permissive and irrevocable Creative Commons CC-BY-4.0 license, as well as WotC's Open Game License. CC-BY has no restrictions on commercial use, doesn't impose the same terms on derivative works, and allows for paper publishing or paid access online.
But the Systems Reference Document, both OGL and CC-BY, explicitly excludes mind flayers from its coverage. For a story including them, you'd have to rely on WotC's discretionary fan content license. If you ever go commercial with it to the point of selling a product, you'll need to contact them for licensing (which they'll be happy to charge for, this being their business).
As to why mind flayers are excluded from the SRD, I can't tell for sure. One reason could be that most D&D concepts are based on prior art (races especially) or aren't copyrightable (game mechanics), making any WotC claims to them weak and easily contestable. No one owns the idea of dwarves or elves, and no one can own a stat block. When WotC considered tightening the OGL, major content makers threatened to create a "same but different" system, which they can, leading WotC to back down.
Illithids/mind flayers, on the other hand, while loosely based on Lovecraft's Cthulhu mythos, were first called by these names and codified by Gary Gygax. That makes them original IP with a strong claim. You still can use them under the fan content license, which applies to mind flayers, but isn't as free as CC-BY or OGL, restricting commercial use.