One distinction I make in what I imagine happening is that while I might be perfectly willing to say, "That doctor sounds like an idiot! I can't believe he said that to you!" I would be much less willing to show disapproval of my spouse to my friend, especially if I hadn't heard my spouse's version of the story yet. So I don't think I could go as far as saying, "I'm so sorry DH said that to you, it was incredibly rude and he owes you an apology. He can be kind of a jerk sometimes," or something along those lines.
Of course, I can say, "I'm so sorry you're hurt, I didn't hear DH say that and I don't really know what he meant." And you can bet when I got home, I would ask DH what was going on, or tell him that my friend was really hurt by his behavior and see what he had to say about it.
To me, "apologizing for a spouse" (as in, "I'm sorry for what he did, it was bad") can start to get into the realm of "taking sides." And if I'm taking sides with a friend against my DH--well, there's bigger issues involved than just that one specific instance, you know?
And one more thing--for me it would also depend on how DH and I socialized with Friend. If instead of a friend it was my mom, who is a very reasonable person that I'm very close to, I would have much, much more interest in DH and my mom resolving their differences (and it would be more likely that DH had done something truly objectionable anyway). But, if it was DH and a friend that I had known before I met DH, who I could socialize with without DH being there, and whose personality is a bit prone to take offense anyway, I would be much more likely to say, "I'm sorry you're hurt. Maybe we should just get together without DH for a while," and leave it up to him if he wanted to apologize on his own.