When it works.
It's not something that has a particular formula. Nothing to count. No threshold to pass or avoid passing.
Use your critique group or beta-readers or your favorite alpha reader. Don't ask them to look at this metaphor but, rather, to just read. If the simile sticks out like a sore thumb, they'll tell you. If they love it, they'll tell you. If they don't say anything about it, then ask.
The purpose of description is to paint a picture in the reader's head. Sometimes straight description can be tedious or it's hard to evoke the right image. Using imagery as narration can sometimes cut to the chase.
Her voice was like butter as she laid out the new, harsh, edicts.
Though sometimes imagery can go too far. As you say, it can "pull the reader out of the story." You want to avoid anything that brings the reader's mind to the metaphor instead of the character.
For instance, my butter example would probably not work in a novel about workers at a dairy farm. If there have already been descriptions of actual butter, especially if butter-making is part of the job, then using that simile changes the meaning of the sentence. Instead of describing a rich, smooth, voice usually associated with warmth in contrast to the harsh words it speaks, you end up with a confused reader thinking back to the last dozen descriptions involving butter and wondering which one to use and what it means for the character.