One of the other lessons that I kind of forgot to apply while running the D&D games is that NPCs should have goals.
Yes, I mean that as a blanket statement. Every NPC in your game should have goals. Those goals might be simple. A merchant you weren't planning on but have to run because the PCs went shopping could just want to make money selling their product. But everyone should have a goal.
Let's take this shop keeper again. Going without a goal, it's just an exchange. The PC wants X, they pay Y and that's it. But if the players are turning it into an encounter the goal can feed into the options the players get. A simple goal like "make money" might be appealed to by the PCs saying they'll advertise the store and talk it up. But what if the goal is to cure a sick child? Maybe now the PCs can get what they want in exchange for a Remove Disease spell.
For a minor encounter it's not the end of the world if you just have very basic or even no goals besides "perform your function." And obviously you want goals for your major story NPCs. However, the place where I often forget to give goals is for combat encounters.
Why is a goal important for a combat encounter? Because it determines the NPCs victory condition. This is what they are working towards just as surely as the PCs are working towards their own victory condition. If you don't set it, every combat is just a fight to the death....and frankly, that gets boring. But spice it up, give them some other goals...and you can get much more dynamic encounters.
Let's consider three different goals all built around the same basic encounter: The PCs are being attacked at night when they've set up camp.
Goal: The NPCs have been sent specifically to kill the PCs.
This is pretty much the same as a no goal encounter. Or is it? A no goal encounter, you start a fight, you have a fight, and maybe it goes bad or maybe it doesn't. Now consider what happens if the NPCs are there specifically to kill the PCs? Are they stealthy at all? Do they sneak up? If so, how much do they know? When do they make their move? Do they go for the person on watch or straight for the sleepers? If someone goes down, and the goal is death, do they go straight for the kill?
Also keep in mind that being sent to kill the PCs also implies some information on the PCs. This can mean a plan - depending on the encounter type - and knowledge of what the PCs can do. That enables you to make a normally less threatening enemy more of a threat, which can in and of itself make things more fun.
Goal: The NPCs are hungry/want food
This can be one of two things: humanoid enemies who are looking for food or coin to get food, or animal/monsters that are looking for food. Either way, this encounter has more ways it can go from the start.
Consider a humanoid opponent. They see the camp. They're starving. They go to sneak in but get caught. Does a fight break out? Possible. But what if they ask for food? Maybe the PCs give it to them, maybe they don't. The PCs can turn this into getting information about the area, doing a good deed,
Considering a beast opponent, it likely goes straight for the food. The fight starts with warding it off whatever it is trying to eat - even if maybe that's someone's boots.
With both of these though also consider that survival is part of the goal. Something that wants to eat is something that wants to live. That means fleeing for animals. It could also mean fleeing for a humanoid, or surrendering.
Also, there is a very real chance the opponent just grabs the food and runs. Now the PCs don't have their food...but the monster? it just won.
Goal: The NPCs are Scouting for a Larger Enemy
This one might not even be an encounter. Then again, it could be a fun encounter depending on who sees. A scout isn't looking to fight, they're looking to report. That means they get close enough to assess the group, then try to withdraw. So what happens when the scout is spotted as it starts to leave?
Maybe the person on watch leaves it alone. After all, it's someone leaving the area. That's fine. Now word of the PCs location goes to a larger force and you can bring another encounter to the PCs. Or maybe it starts a chase. Now you have people running through the wilderness at night. I'm sure nothing dangerous can happen there.
Have Fun With It
That is one type of random encounter that can go three ways just with changing the goal. Those answers aren't even the only way those things can go. Add Goals to your encounters though. Not for you, but for the NPCs. Give them a reason to be doing the thing. See how it changes how they play. Who flees because some coin isn't worth someone dying? What happens when the hungry guy gets spotted 50' from camp and everyone is now awake and armed?
Let it play out. It doesn't all have to be combat to the death.