Through DM magic
What you are suggesting is entirely in the realm of DM storytelling. There's no mechanics in the game for killing or trapping gods.
In the more of various D&D settings, there have been similar events:
Tharizdun is a god of destruction that was imprisoned in a demi-plane to keep it from destroying existence.
The Kobold god Kurtulmak was imprisoned in a maze by the Gnome god Garl Glittergold.
The Dead Three were mortals who convinced the god of death Jergal to step down and to give them their power. They were later killed during the Time of Troubles.
One of the biggest dead god events would be the death of Mystra, who was assassinated and which caused the Spellplague to happen because the Weave is connected to Mystra.
Karsus was a mortal who thought he had to save his realm by taking on the mantle of a god, and he cast a massive spell that killed the goddess of magic (she never gets a break) to gain her power. This ended up causing magic to go haywire, because he had no idea how to keep the Weave running and he drastically underestimated how much a god does. The end of his country from the resulting magical failures is known as Karsus's Folly. That said, Mystra has since made magic as powerful as that impossible as far as most mortals know.
In other words... it is possible to trap or kill a god, but there are no defined mechanics and it's essentially DM storytelling. Come up with a reason that sounds plausible to you and your players and nobody will complain that "that is not how it works".