There are no rules for this, but the DMG does have a few suggestions about "backup characters"
The DMG doesn't include any hard-and-fast rules that address this issue in detail (and neither does Xanathar's Guide to Everything).
However, it does briefly touch on the idea on a tangentially related section of DMG p. 236 titled "Small Groups". The section is primarily focused on campaigns with a small group of players, proposing that each player (who feels comfortable with it) control multiple characters, or that the DM fill out the group with NPC followers. However, it does add this suggestion at the end:
Multiple characters can be a good idea in a game that features nonstop peril and a high rate of character death. If your group agrees to the premise, have each player keep one or two additional characters on hand, ready to jump in whenever the current character dies. Each time the main character gains a level, the backup characters do as well.
This guidance suggests that if the player's character dies, the backup character would be the same level as their original.
However, there's another mention of "backup characters" on DMG p. 92, under "Low-Level Followers":
Your campaign might allow player characters to take on lower-level NPCs as followers. For example, a paladin might have a 1st-level paladin as a squire, a wizard might accept a 2nd-level wizard as an apprentice, a cleric might choose (or be assigned) a 3rd-level cleric as an acolyte, and a bard might take on a 4th-level bard as an understudy.
One advantage of allowing lower-level characters to join the party is that players have backup characters if their main characters take time off, retire, or die. One disadvantage is that you and your players have more party members to account for.
Since lower-level NPC party members receive equal party shares of XP, they will gain levels more quickly than the adventurers (the benefit of studying under such experienced masters), and might eventually catch up to them. It also means the adventurers’ advancement is slowed somewhat, as they must share their XP with an NPC shouldering only part of the adventuring burden.
This suggests that a player's backup character might not necessarily be the same level as their original character. (It also assumes that the DM built the NPC as they would build a player character rather than as they would normally build an NPC.)
It's up to the DM
As the DM, it's ultimately up to you to decide whether to let the player swap their character out for another character of equal level. You can also talk to the players to see how they feel about it.
Remember that the point of D&D is to have fun, so the goal probably shouldn't be to force a player to continue playing a character they're not enjoying... But on the other hand, it can be difficult to be immersed in a campaign or tell a coherent story - especially a character-focused one - if players swap out characters too often. (And, of course, figuring out how to explain the character change in-universe is its own problem.)
Ultimately, this will need to be a conversation between the DM and the players. Do what feels right to you and your players.