Designing combat encounters that are fun, interesting and challenging is not easy. I don't claim to be perfect at it, but I hope that I can at least help a few people by sharing my general method for thinking about combat encounters. It will be high level so that it can be used for any system.
The concept of time and timing is an important part of plotting a campaign. For that reason, it is a far broader topic than I will cover today. Still, the timing can have a great deal of impact on a combat encounter. For the purposes of this piece, I don't mean the physical time (night, day and visibility in general could be considered as part of the environment) but instead the timing of elements in the encounter and the timing of the encounter in regards to the campaign itself. A showdown with the villain may actually be 3 encounters where in the first encounter the players are just trying to escape, in the second one they will try to escape but first do something that will inhibit the villain, and in the third and final one will be when they finally win (the timing in the campaign that these encounters happen can contribute to the tension and excitement). It's also important to note that not every enemy needs to be there at the start of an encounter. They can call for reinforcements instead, which can make combat easier but also more dynamic (4 soldiers followed by 4 reinforcements in 3 rounds is easier to deal with than 8 soldiers at once).
In a campaign, there will be an overall theme. I won't go into too much detail here today, but themes that can be incorporated into an encounter help tie it into the rest of the world. If themes are broken, it can even be jarring (though sometimes that is the aim). It can include things such as enemy types (undead, for example), locations and ways combat will play out (do you reward retreats?).
Now that I got the context out of the way, let's talk about designing the encounter itself.
The composition of the party as well as their general experience will play a role in what is considered a good encounter. If the players are too inexperienced, an encounter designed for experience players may be too difficult for them. At the same time, some encounters that end up being fairly dynamic for one party may break down because of certain abilities or strategies a different party could employ. When designing an encounter, be careful to consider possible holes that the party has that may make things harder than you intend (missing healing, magic, etc.). Also note the strengths of the party, their general experience and their ability to think outside the box.
The things that the party will fight will contribute to how dynamic the fight is. Mixing different abilities together can create completely new situations for players to tackle even without considering other factors. As the Dungeon Master, you can also add a couple of modifications to the creatures to change things up a bit (maybe some enemies will use nets, or there's an eldritch knight who uses teleportation to get close to wizards). That's not to say that a crowd of kobolds can't be fun to fight. However, if they've been doing this for multiple encounters in a row, some variety may help (even if it's through a wizard kobold).
Fighting in an open plane is distinctly different to fighting in a 20 foot by 20 foot room which is distinctly different than fighting on a 10 foot across bridge. Thinking and implementing good environments is partially an art. However, at the very least cover and elevation need to be considered. Both of these are instrumental in breaking up static strategies (fighters block the tunnel). It's also important to make sure the baddies you populated the environment with use the environment to their advantage if they are intelligent or don't at all if they are unintelligent. You can also throw in a couple of unique features into your environment. Teleporting environment features are a good example, since they help break up the usual environment and break the rules. I've also seen special material deposits that reflect magic, make magic weaker or even empower magic. The point it to consider how the environment will change tactics and to use it to make combat more interesting (this also means that there needs to be a benefit to using the environment in creative ways or at the very least it should be memorable).
I previously mentioned reinforcements coming after 3 rounds. That would be an example of what I call a twist. It also related to timing but there is no problem with multiple parts of my model overlapping. In my model, a twist is a feature of the encounter that is outside the enemies, players and environment that helps make the combat different. An earthquake every 1d4 rounds is an example (it may sound close to environment and ideally all of the elements should combine together to make a seamless whole, but I tend to consider the environment as a bit more static). It could be a plot point as well (big bad wizard turns out to be a big bad lich wizard in disguise). The most common thing, however, is to add some kind of goal besides beating the other guys. Interrupting a ritual, chasing after a certain character, or even destroying the entire room could all be used to change the flow of combat (obviously, if the players are trying to bring the entire place down it will be a different experience than just beating the bad guys). The twist, depending what it is, could make the encounter easier or harder (bringing down an entire temple by knocking out the support pillars could make it easier since the players wouldn't need to defeat all the cultists, or could make it harder because of how hard a pillar is to destroy and that more shadows will come until the temple is destroyed). It could also be a non-combat puzzle that needs to be accomplished to seal away the demons (I'm quite fond of non-combat + combat encounters).
I hope my model of using time and theme as considerations as well as the players, enemies, environment and twists helps plan, analyze and inspire combat encounters. It is still challenging to come up with dynamic and memorable encounters, but I think every little bit helps. As always, feel free to comment.