Let's say you make your character use a special magic wand to kill his opponent, but you forgot to mention and describe what the wand was, can you do a flashback as soon as your character brandishes the wand or after he uses it? If it's a bad thing to do, what can you do to make it work since there's no going back when you wrote the story and it was already published (novel series, television episode, etc.).
Not really, it is not ok. You can do a flashback; but it will still seem to the audience a deus ex machina.
Readers aren't stupid and they expect characters to survive by wits, not luck. This seems to be a situation where the writer didn't know what to do, so they come up with a flashback that is so important it should have been mentioned before, and oh so conveniently saves the day in what looks like an unwinnable situation.
Think 007, he is always getting out of scrapes with magical-seeming devices, but the authors are always careful to have Q, before the mission starts, provide him with just the equipment he will need later in the show. An exploding watch that can destroy a room, carbon nano-fiber that can cut through steel, machine guns behind his headlights, a driver's seat that ejects with a parachute in the back, so 007 can drive off a cliff if he needs to (and of course he needs to). Even that is recognizable as a deus ex machina, Q is a bona fide fortune teller to predict so accurately what 007 will need.
If you have written yourself into a corner, put a scene early in the current work which still can be changed, to provide the hero with something that will preferably assist them in getting out of the scrape. Preferably, it is not a cannon, but perhaps some sort of innocuous distraction. Instead of a magic wand, say a magic coin. And it doesn't kill the bad guy, when the hero tosses it into the air, it flashes so bright it temporarily blinds everybody with their eyes open. The hero closes his eyes, tosses it, and has a few seconds to do something the villain cannot see, including rushing and killing the villain. Even the hero, when he gets it early on, isn't sure what it is good for, other than a party trick. What can I do in two seconds? (Well, turns out, stab somebody in the throat that cannot see you coming.)
This trick or some other, do not ever make it easy on your hero. The hero must be the one that thinks creatively under pressure and comes up with how to use the party trick to win the battle.
Even my example, off the top of my head, is probably too obvious. You have the advantage, as an author, of being able to think all day about a non-obvious use of a magical trick we would not expect in battle, that your hero can then think of in an instant. The more clever and unexpected the use, the more delighted the audience will be. So write an early scene where the hero acquires some magical item that seems useless in battle, but provides him the distraction he needs to escape or defeat the villain.
If you really are releasing your story in pieces, and at the high point of piece #7, you want your character to use an item that they must have obtained back in piece #3, but you didn't mention in piece #3, don't interrupt the action to flashback and explain where the item came from. Make it a mystery. Describe what's happening (a glow coming from the character's hand, or the opponent just freezing in place for no apparent reason) and all the consequences with little exposition at all. Then, when the excitement is all over, have another character (representing the audience) ask "what was THAT?".
At this point your character can explain why this is in fact not a total surprise you just pulled out of nowhere because you didn't have a good way to end the battle. Ideally, this explanation would refer only to things you showed the audience in earlier pieces (say an aside in narration about 3 days of boring training we would never need, or a dumb heavy pack they all have to carry for no reason) that now gain significance as the character explains them. But if you're really stuck, it might be enough that the other character already knew about them.
What was THAT?
A thermo-thauma bridge, of course. [Cheerful smile.] Mediated through a pencil because that's all I had. You didn't skip the third day of thermo training, did you? That's when it really got useful.
The first two days were so boring, I went to the health centre and got a skip note.
Well, I bet you're glad I didn't!
It might take you a while, but look back through your earlier pieces for some "blah blah blah" moments like training you don't describe, reading you don't describe, annoying packing or supply lists, and see if you can pretend you meant those all along to be foreshadowings of this moment.
In general, having a huge crisis resolve quickly and very easily, relying on something not previously shown to the audience, is a deus ex machina, a god in the machine, and not a good thing. We have a number of questions tagged with that. The key to DEM prevention is foreshadowing, and this question is specifically about what to do when foreshadowing isn't available to you. Still, reading those questions may give you some more possibilities, or help you tone down that last-minute "oh yeah, I do have this magic wand in my pocket that I never mentioned before" that strains credibility.
There is another option which is to build up the item as the crisis builds. Like something is warm, or vibrating, or I-can't-explain-it-but-its-calling-me in the hero's backpack, or sewn into the lining of a coat. [Ideally you can call back here to something the audience did see when they got their backpack or picked up the stick for another reason.] Eventually our hero has to stop whatever crucial thing they're doing to pick the item up, causing some mini crisis like losing their weapon or getting separated from the group, and things get worse, and the item glows brighter or whatever, and then it ends up in their hand (since they don't have a weapon) and then -- BLAMMO! -- so the hero discovers this amazing power at the same time as the audience. But that is much harder to write.
Another way to avert sudden death is to have something random interfere, such that the coup de grace is spent and the villain caught off-guard.
Example: hero is bound in a chair, and the villain points a gun at the hero's head. The chair unexpectedly breaks a split-second before the villain pulls the trigger, making the bullet miss and partially freeing the hero, who then scrambles away in the two or three seconds it takes the villain to process what just happened.
To disguise and mitigate the deus ex machina nature of this sort of thing, make the event (1) not caused deliberately by intelligent actors, (2) kind of unpleasant for the hero, and (3) merely avert the worst rather than completely turning the tables.
In the chair example, the chair presumably breaks because it is old and under special strain because it's tied to an anxiously writhing human. This could be foreshadowed in the current episode by describing creaking sounds as the hero is tied to it, or by pointedly noting the decrepitude of other objects in the area when it is introduced, or even by having the hero mentally contemplate the way their own body will decompose when it's left here after their execution.
In a scenario where the imminent danger is a magical attack, perhaps it's enough simply to distract the villain with a sudden beam of light caused by the rising/setting sun, or with a suspicious noise from another room that prompts them to pause out of caution or fear of discovery. Or even an allergic sneeze, which then does double-duty as character development for the villain.
Why the need for having the flashback "as soon as your character brandishes the wand or after he uses it"? If you have your character use it in a part of a series, if it's in a pivotal moment, it likely doesn't happen on the first page or during the first few minutes of the episode. Even if the whole story is broken into separately published parts, each part has a climax of some sort in the later stages of it. Therefore you can have your flashback early in the episode, and have your character use the power received in the flashback, somewhat later in the episode.
There is quite an unkind word for cases where a surprising and hitherto unknown new power is introduced right in the moment it is needed to overcome an obstacle.
I've seen this work where the idea is the author or first-person narrator deliberately hid it from us until the last second, to make the story more exciting. A nice way is to not show the escape gimmick yet. Just flashback and explain how they suspected a trap, who they talked to next, where they went after that (maybe to an underused character who we enjoy seeing again). As readers we don't see where this is going at first, which makes it fun when we realize they're explaining the surprise up their sleeve in the present. A key is to have the story make at least as much sense with the sudden reveal. In your case he's walking defenseless into an obvious trap -- oh, he's not defenseless, he was just fooling the bad guy the same way he fooled us.
The pretty sure the old Mission:Impossible TV show did this. After the bad guy saw through their plan at the end, they flashed-back to show the plan's second half, so actually they did fool the bad guy. That was fun since it felt like the best way to explain the plan-within-a-plan without confusing us.
One of the Dresden Files books did it just nakedly, and those sold pretty well. We're at the final climactic scene where he's about to die, and we get a whole series of flashbacks of the "I suspected a trap and here's how I prepared" that was hidden from us earlier. It more-or-less works as writing partly since the sudden reveal merely evens the odds, and also the "is he seriously just walking into a trap?" thing.
So your protagonist has just killed a villain with a wand from seemingly nowhere. Surprise!
Of course, there's nothing wrong with a good surprise. After all, everybody remembers the moment when Darth Vader turns and tells Luke Skywalker: "No, I am your father." But you're here because you have a feeling your surprise isn't quite that good, quite that well-earned. (Few have been.) Alas, if you had planned better, this surprise could have been the pay-off of some brilliant plan years in the making! Now you have to explain where this wand came from and what it's doing in your story.
Well. A slightly more positive way to think about it is that you've just taken out a loan. You've asked your readers to lend you some credibility. That's okay! All writers do that. No story was ever fully foreshadowed in the first three paragraphs. But now, you must make good on that loan.
You need a pay-off.
Perhaps the wand is less deus ex machina and more phew ex machina -- instead of killing the villain outright, it simply gives your hero enough breathing room to make a cowardly retreat. Perhaps your villain simply feigned death, and is now plotting a dastardly revenge in a suitable evil lair. Perhaps the wand was a once-off and broke in half after that. Why, the wand probably took your hero's arm with it in the process! Or the power your hero summoned with the wand siphoned off the last dregs of power from the seal on the tomb of McTerrible The Even Worse Demon.
The point is, any surprise can be forgiven if, moving forward, the story is better for it. Make your surprise small and its pay-off great.