Based on the rules, yes, any enemy that is part of the encounter is counted to the XP that is awarded, no matter if they are killed, sent away screaming, or snuck around.
Each monster has an XP value based on its challenge rating. When adventurers defeat one or more monsters — typically by killing, routing, or capturing them — they divide the total XP value of the monsters evenly among themselves.DMG p260
A dead monster is a dead monster.
What is in an encounter?
Which brings us to another technicality: what is part of the encounter? Any monster that added to the complication clearly is in the encounter. But monsters that are merely set-dressing are more dubious. Let me prop you an example:
You stand in an arena. Goblins fill the ranks above you and cheer their champion, the Ogre Munchies. As he roars, they cheer even more. The sound becomes ecstatic as he lifts a heavy rock and throws it into the crowd, turning two Goblins into pulp.
Are those two goblins part of the encounter? Well, no. Those two are set dressing, the actual encounter is the Ogre. No XP for the non-encounter monsters that never opposed the players.
If the two Goblins however were down in the arena, they'd be part of the encounter. But even then, granting XP for them should not happen at all times: if the two were put in the team of the players' team, they are not adversaries to overcome, no XP. If they are killed by the script before the whole encounter starts (in the establishing shot so to say), they are set pieces and not actually in the encounter, no XP. But the moment initiative is rolled and the encounter begins, any monster that is part of the encounter and that is killed, counts.
However, the Friendly Fire actually should costs the heroes some XP. Say the two goblins give 100 XP each and the party is 4 people. If they kill them normally, each hero gets 50 XP (=200/4). But instead they die due to Munchies throwing that rock right after the encounter began. He acted as an Ally for the kill of these two goblins, so the party size is 5, resulting in only 40 XP (=200/5) per character, Munchies included... Likewise, as long as some of the (3rd party) Goblins do something against Munchies, the party size that counts for the XP distribution needs to get adjusted. This can really get wonky for 3-party battles like in the arena described. Why? because the DMG says:
If the party received substantial assistance from one or more NPCs, count those NPCs as party members when dividing up the XP. (Because the NPCs made the fight easier, individual characters receive fewer XP.) DMG p.260
Nothing here says, that the NPC needs to be an ally or be friendly, unlike Thomas Markov claims. Killing someone is definitely substantial assistance under the standard English definition of assistance being "the action of helping someone by sharing work". Since nothing in that guideline precludes that the enemy themselves can be an NPC that assists in the killing, the XP are technically to be shared with the NPC's that do friendly fire.
When is something not in an encounter?
Yet, if the enemy dispatches of their own troops to show how evil they are, you, as the GM, might feel justified to exclude them from the encounter. My personal stance (heavily formed by experience campaigns that put the focus on the story and characterplay) is, that as long as they don't have posed any complication for the heroes, I would not award XP for them and class them with the set pieces that are killed in the establishing shot of the encounter. That's even if that happens well after the combat began. But if the players actually fought them, they are an obstacle that was overcome and worth (some) XP.
Let's say the group faces 10 Kobolds, and after the party killed the fifth this happens:
A voice from somewhere a deep, booming voice that shatters confidence and clearly is spoken in capital letters speaks up. There is no emotion in the tonality as if whatever it belongs to has no emotions since the dawn of time.
The next moment, the air around the remaining Kobolds shimmers, rapidly freezing and leaving them trapped in pillars of ice, pieces of art and death.
Whatever icicled the Kobolds was an ally in that instance, as the group had to deal with them moments earlier. So the group needs to share the XP with it, according to the quote above. Booming Voice gets a share of XP for those 5, but not the others dispatched earlier without his help. However, if the group fought only 5 Kobolds and the other 5 just showed up as reinforcements that had yet to act, the additional ones posed no risk or complication. That means they are not part of the encounter. If anyone, the Booming Voice would be the one that gets XP for all 5 of the second batch.
This interpretation (of not rewarding XP for bystanders and set-pieces) is something that I was taught by other GMs and has been used in games since at least the 3.5th edition. (In fact, I have never seen XP granted for kills of Set-Pieces). The approach was possibly heavily influenced by The Dark Eye. Generally, TDE does grant the Experience for plot performance, which might include dispatching enemies, but not for the actual kills, as I had explained here. D&D uses in the main an encounter-based method of Experience. 5E puts the emphasis on solving an encounter, such as dispatching an enemy, disabling a trap, or navigating tricky passagesDMG p261. A group of potential enemies however isn't an encounter, and if they are slain without the player's action, they have not actually (assisted in) solving the problem. Having not done anything, there is nothing that is rewardable. A telltale that was used to explain to me why neve to grant such XP was, that granting XP for any death around PC's would result in someone getting the idea to bring the plague to some city to just level up passively because enemies die around him.