Developmentally speaking, children this age are discovering the power of words. However, what they don't understand is the full emotional impact of the words that they do use. Add to that the fact that they lack the subtlety of expression that adults have: "I'm really irritated right now" can come out as "I hate you poo-poo head". Finally, add to that the fact that they often lack filters. When adults sit next to someone who smells on the bus, we don't usually announce "ewww....you stink!" 5 year olds do. They say whatever is on their mind, which is why my 6 year old wrote on her thank you note to her teacher: "I never thought I'd learn a thing from you, but I did!"
When you add all these things together (learning the power of language, not getting the impact of their words, lack of subtlety and no filter), you get 'mouthy' kids. Because of that, I think that as parents, we have to learn not to take this personally. It's not personal, it's developmental.
Now, that doesn't mean that these kids don't have things to learn, and we definitely need to help them learn how not to sound so rude. But I think if you view your task not as quelling defiance but teaching a child how to express their opinions politely, you'll have an easier (and more productive) time. I remember being incredibly frustrated as a child because I was told that I was being sassy, and whenever that happened my parents weren't listening to my ideas. For kids this age, we need to separate out the ideas and feelings from how they're being expressed.
Several things help me with this (and no, I'm not always perfect, and yes, I do sometimes descend to my 6 year old's level )
-The ideas in How to Talk So Children Will Listen (and Listen So Children Will Talk) by Faber & Mazlish -- the whole rephrasing what they're saying, rather than jumping in and fixing it/answering them -- "It's sooo unfair! I never get a chance to do this! T always gets to help daddy outside!" "Oh, it sounds like you're really disappointed that it wasn't your turn to help pull weeds for chores tonight." That helps my daughter feel heard, it models a less dramatic interpretation of the events (she does get to do this, it just wasn't her turn and she really didn't want to pick up her bedroom, which was her chore that night.) Non-violent communication is also really good.
- Modeling, modeling, modeling, as others have said. Not only modeling, but directly teaching them when they've been rude. "Get me a glass of water" was met with "Is that the same as "Can I please have a glass of water, mom?" If I'm feeling playful, I might say "Oh no, no no. You need to say "Darling mother dearest, light of my life, could you kindly interrupt your busy schedule and honor me with a glass of water?" It breaks the tension.
-Pointing out when they're rude and asking them to rephrase. At this point in time, my kids know how to phrase things politely, but they sometimes fail to implement it. So, an oft-heard phrase in our house is "That was rude. Try again." or "How can you say that politely?" So, OP, if your daughter has something that has hurt your feelings, why wouldn't you tell her that? My kids have heard "That was very rude. I don't like to help you when you're rude" more than once.
-Sending them away to cool off. If they're being rude and insufferable, it's a clear indication they need to cool down. They get to go off to their room until they can be civil again. Or if we're driving in the car, they can be quiet for awhile. I do believe I announced to my two children in the car "I don't want to hear anything from either of you until we get there because you are both being very rude." It was my version of "go to your corners and cool off".
OP -- if it happens often at the end of an activity, I would think about one of two things. It could well be that she's mentally tired from interacting with other kids. I'm an introvert in a profession that requires a lot of extroverted behavior (teaching). The absolutely most exhausting days I have are days when I spend all day meeting with students. When I'm done with those meetings, I am one cranky momma. I need down time. Now, I'm also an adult, so I'm not usually rude to people to get that time, but I have been known to snap at my kids. Or, it could be that she's an extrovert (like my dd). If that's the case, she gets her energy from interacting with people, and she's suffering a let down afterwards. So, she's doing all she can to keep up the interaction. For some kids any interaction is better than no interaction. My ds will happily go off and play by himself. My dd will bug someone when she's tired.
I guess the point of my huge post here is that I wouldn't dwell too much on the why. This doesn't represent some deep-seated psychological need, IMO. It represents a need to learn how to use language appropriately, especially when emotions are running high. I know a lot of adults who lack adequate skills for that!