The world of magic
In D&D the world is supposed to be a magical place:
In most D&D worlds, magic is natural but still wondrous.
Some D&D settings have more magic in them than others.
Whatever mr. Clarke says, magic is not technology — the former is wondrous and can't be replicated or harnessed in a convenient way. The uniqueness of relics and places of power is the common fantasy trope.
From the balance reasons merging two magic items is the same thing as finding a third more powerful one. And finding new magic items happens quite often in a D&D game. A DM can (and should) introduce their own magic items using the Creating a Magic Item guidelines from the DMG p.284. The same is true for monsters, by the way.
So you can just introduce a kind of "Crucible of Merge" somewhere in the world which allows you to transfer some of one item's properties to another one, while staying in the 5e guidelines.
DMG page 141 "Special Features" actually encourages this approach:
You can add distinctiveness to a magic item by thinking about its backstory. Who made the item? Is anything unusual about its construction? Why was it made, and how was it originally used? What minor magical quirks set it apart from other items of its kind? Answering these questions can help turn a generic magic item, such as a +1 longsword, into a more flavorful discovery.
So here is your +1 Longsword of the Flame. It was constructed by PCs using the Crucible of Merge by merging their old +1 Longsword with the Flame Tongue.
Pact of the Blade
Warlocks have a feature that gives them their own magic weapon:
You can use your action to create a pact weapon in your empty hand.
This weapon counts as magical for the purpose of overcoming resistance and immunity to nonmagical attacks and damage.
This weapon is supposed to be a main melee weapon of the Warlock. However, if she finds a better magic weapon, she can transform it into her pact weapon:
You can transform one magic weapon into your pact weapon by performing a special ritual while you hold the weapon. You perform the ritual over the course of 1 hour, which can be done during a short rest.
This way the weapon retains all its properties and it also gains special Pact of the Blade properties, so it is like "merging" weapons together:
You are proficient with it while you wield it.
You can then dismiss the weapon, shunting it into an extradimensional space, and it appears whenever you create your pact weapon thereafter.
Keep in mind you can't do this with the most powerful ones (so called artifacts).
The Wish spell
One of the most powerful and controversial spell which allows you to do anything. With the acceptance of the DM a player can merge two magic weapons into one, gaining the more powerful and unique magic weapon. Basically use the same Creating a Magic Item paragraph when adjudicating this.
It's not a good idea to combine many magic items tho
There is no convenient way in 5e to merge different magic weapons and there is a reason for that. Let's say we have +2 sword, a Flame Dagger with additional fire damage and a Staff of Defence giving you +1 to AC. Players are not supposed to merge them into "Flame +2 Sword of Defence" with all the properties combined, primarily because of the balance reasons. You can allow it as a DM, but this will quite definitely break the game.