Wyll the warlock may not be our favorite Baldur's Gate 3 companion, but that's only because the overall standard is so high. In any other RPG he'd be a top pick, and even in Baldur's Gate 3 he's worth keeping around. It's just a shame you can't complete his personal quest, which earns you a sweet Infernal Robe and prevents him from growing a pair of horns, without killing Karlach, who is everyone's number one fave.
Except you sort of can. The sequence of steps necessary to thread this particular needle has been figured out by various folks, including Leyllara on the BG3 subreddit. Here's how it works. First, you recruit Wyll and get the quest to kill Karlach on behalf of his fiendish patron, Mizora. Then you leave Wyll at camp and kill Karlach without her realizing you're the one who did it. This is tricky, but can be done by attacking from range, or casting a hold person spell. What you want is for the barbarian to drop before her dialogue triggers. You can also disguise yourself before attacking, which may be tough at low level unless you've got the Mask of the Shapeshifter from the digital deluxe DLC.
Make sure Karlach dies in a position where she can be resurrected later, which you can test by activating a Revivify Scroll and mousing over her corpse. Don't resurrect her just yet, though. Instead, go back to Wyll and tell him the job is done, and only then return and resurrect Karlach, again from a distance to avoid triggering any dialogue.
At your next long rest with Wyll in your party, the devil Mizora will arrive to reward him for murdering Karlach, handing over the Infernal Robe instead of cursing him with a pair of horns, as she does if you spare Karlach like a normal person who isn't gaming the system. Finally, return to Karlach and recruit her. She and Wyll will argue, but you can convince the warlock Karlach isn't evil and he'll agree to spare her, as usual.
While the rest of the game should play out as it's supposed to, there may be some bugs. Most notably, during the tiefling party scene after you save Emerald Grove, Wyll acts like he's done something horrible. As Redditor and self-professed "Karlach #1 Fan Girl" Meikos put it, "Wyll still mopes at the party about having killed Karlach as he normally would, despite the fact that she's several meters away dancing."
Still, despite some dialogue hiccups, the important thing is that Wyll stays uncursed and you get a sweet robe that grants resistance to fire damage, +1 to armor class, and the fire shield spell, which gives you resistance to cold damage and deals 2d8 fire damage to anyone who hits the wearer in melee. Technically you did kill Karlach to earn it, even if you resurrected her after. Loophole! And you don't even need to turn anyone into a sheep to get it.