I am considering writing a line of dialogue in which character A calls character B (not to their face) "a lunatic". In the context of my story, it is clear that character A has a simplistic understanding of character B, and therefore character A's assessment of character B as "a lunatic" is incorrect. Additionally, character A is established to be a judgmental person. Would it be okay for me to use this line or should I scrap it entirely? Basically, I'm wondering if "lunatic" would be considered an ableist slur? If so, what should I replace it with?
Some may call it so, and they might be right, but it's of no consequence.
Creating realistic and believable and sympathetic characters means that sometimes those characters have negative character traits like being sexist, mysogynsist, misandrist, ableist, dishonest, self-agrandizing -- any ist you could possibly imagine.
That is because people can be these things.
What matters is that the characters are interesting and that their good traits and bad traits are important to making the story go forward in an engaging way, or part of the story resolving in a satisfying way. If you make a character a wisecracking misandrist just so you can use your ready supply of men-r-jerk jokes, and her misandry doesn't add anything to the story, then it's not a great choice, no matter how hilarious she is.
And, time and setting play a part selecting character traits and attitudes towards insanity, amongst other things. A character from the 16th century might see someone's madness as god's curse. And, a character from the Progressive Era Socialist World 1984 might see them as maladjusted. The language character's use devolves from their worldview.
So character A is an ableist.
No problem. Your writing should have characters that are jerks, liars, cheats, criminals, murders, and more or less bad people of all kinds and types.
And some of them are called antagonists and without antagonists, you'll have problems with conflict.
OR, maybe your story's conflict is about character A thinking of character B as "a lunatic". Maybe character A follows an arc where they go from being an ableist to being a person that sees the world in much better detail. Maybe they don't.
If your message is: "don't be prejudiced" then you simply "punish" character A for their prejudice and you've got a message!
Readers will think of your characters as part of the story and if the story demands they say or do things a certain way, if it's done well, they will say the story was a good one, if it fails they'll say it was a bad one.
If the message of your story is prejudiced, on the other hand, then they'll think you are too.
It's not even a problem when the narrator is prejudiced, as long as it happens on purpose:
And then there was B, he was one of those complete lunatics!
Does that make me sound ableist? Or does it sound like the narrator is? Would it have been different if I'd just started my answer like that? Does the fact that it is written as fiction (talking about a fictional person and marked as a quote commonly used on Writing to mark fictional passages) make a difference?
I think the only way to come across as prejudiced as a narrator/storyteller is if you do your research so badly you show prejudice by your lack of understanding of people. Extreme example: all the black people in your story always sing and dance... or all the Scandinavian female characters have D-cups and sleep with everyone... or well you get the point.
Sometimes you have characters that use bad language and do horrible things, and without them, your story and your message will be worse off.
After all, "Schindler's List" would have had problems without the Nazi characters...
I would probably say not really. "Lunatic" and "crazy" have specific real-world connotations, i.e., having a mental state that is completely detached from reality. Most mental disorders (autism, depression, OCD, ASD, etc.) aren't characterized by that. The only ones that could be are schizophrenia and Narcissistic Personality Disorder, but I don't know how you could come up with a term describing someone divorces from reality that doesn't include a benign individual with schizophrenia that just needs their meds to be functional and someone like a dangerously deluded fanatic or ideologue who is a threat to others because of their beliefs.
The other issue is the fact that most slurs have shifting baselines. The terms "moron", "idiot", and "imbecile" were all originally terms that were used to refer to the mentally handicapped that have since become broadly applicable and benign, whereas "retard", which was coined originally to be a clinical, more sensitive alternative to "moron" or "idiot" (i.e., "mentally retarded") has since become a slur. What is and is not appropriate to call someone now might not be appropriate by the time you are finished writing your story.
There are many words that you could use to define "lunatic". Unfortunately, you're not giving us much of a background and surrounding to go with. There are words that could be used based in a periodical sense as well as cultural.
For example, in the 80s & 90s, the word "weird" or "flaky" was used more often. In the early 20th century "queer" was popular. In Victorian times, "eccentric".
Words with cultural influence, for example, "mishegas", sometimes spelled "meshugas" or "mishegoss", is a Yiddish word. In the UK, the words "bonkers" and "balmy" are used often.
As well, if Character A is prone to idioms, they could blurt out "not playing with a full deck", or "he’s about half a bubble off plumb".
Hope this helps and good luck.