1. Create a new character on the spot
Building a high level character tailored to a particular game can take quite a while. But making a simple first level character in DnD 5e normally doesn't take overly long.
2. Use a previously generated character
There are lots of sources for character stats that fit the rules quickly including pre-gen characters in official books, and fan made ones. You can also reuse the stats from the last character and change the name and backstory.
3. Restore the character
DnD has all kinds of ways of resurrecting a character within the rules. It sounds like you are the DM, so while it may be a little bit of deus ex machina it would not be hard to have one of those methods conveniently fall into the groups hands shortly after a character died "too early". The way it falls into their hands may mean that there are consequences to using it though. A high level NPC cleric for instance may offer to do it in exchange for a favor that is a plot hook for the next stage.
4. Ban character death outright.
This is more of a tangent than a direct answer, but it would prevent the problem.
When I serve as the DM I normally focus on plot over combat and encourage my players to develop elaborate back stories. To facilitate that, I outright ban PC death unless it is a deliberately chosen heroic sacrifice. Losing a combat will always come with consequences, otherwise it wouldn't be fun, but those consequences never end the campaign for a PC.
This is surprisingly easy most of the time without even bending the rules because most intelligent opponents will prefer to capture than kill for reasons including ransom and interrogation, etc. If the rules say a character would clearly die then I do have deus ex machina step in. Sometimes, especially in low levels, I will simply declare them injured and unconscious but not dead. In higher levels, the party will often have ready means to methods to raise them. If necessary in DND, I may literally have a deity step in to save them but in a way that the deity will expect to be repaid later.
As long as losing still has some real consequences, I find this doesn't detract from the excitement of combat that much while it helps avoid the issue you raised and also encourages the players to invest in long term story development.