The cause of the attack was the Dwarves' desire to possess the Silmaril, set in the dwarven-made jewel, the Nauglamir, for themselves. After the two treasures were brought together, Thingol sought to take it and set about it his neck but the Dwarves withheld it from him, saying that he hadn't the right to do so as it was a dwarven heirloom taken from Nargothrond by theft. Then in a gesture of great pride, Thingol scorned the dwarves as inferiors undeserving in comparison to himself and proceeded to speak ill of them, deeming they should be gone out of his realm forever. Insulted and ever wanting the Silmaril, the Dwarves' hearts kindled to rage and they fell upon him and there was a great battle within the palace, Thingol was seemingly defeated, and the Dwarves of Nogrod took the Nauglamir and the Silmaril, but were driven out of the fortress.
The Dwarves left Menegroth, but it didn't take long for the alarm to be raised on what had been done, and soon all of Doriath was roused. With great wrath, the dwarves were pursued to the death and all but two returned home to Nogrod. When they arrived, the survivors lied about what really happened, saying that their brothers had been slain at the command of the Thingol, hoping to cheat them of their reward. The Dwarves of Nogrod then became filled will wrath and desired revenge. They tried to get the Dwarves of Belegost to help them but they refused.
Later the Dwarves were allowed past the Girldle with the help of treacherous elves who were under the curse of the treasure. Meanwhile, Thingol was lured out of the fortress on a hunt with only a small company of arms. The dwarves were waiting for him an ambush finally slew the king, and the fortress of the Thousand Caves was taken unawares and plundered, bringing well nigh to ruin the glory of Doriath.
Melian, full of grief and pain at the loss of her husband and seeing that that the doom she had so feared had finally come upon Doriath, withdrew her protection of the realm. The dwarves could neither harm nor seize her and she went forth...
Here there is a split in the accounts...
In Beren and Luthien (2017): Sought after Beren and Luthien, to warn hem of the Dwarves approach. Giving them a chance with help of the Green Elves to stop the Dwarves at the battle of the Stony Ford. Melien also tells Beren the dangers of the Mim's cursed treasure and has discussions with her daughter Luthien. She gives the Silmaril to Beren for safe keeping. In time Luthien faded, and Beren died, and their son Dior became heir to Doriath (taking the Silmaril with him) and helped raise its glory anew, though Melian dwelt in that place, and she returned back to and of the Gods.
Alternatively another somewhat later account (closer to how it appears in The Silmarillion (1977)) Dior leaves later while his family was still alive and become the new king of Doriath. It was when Green Elves brought him a coffer with the Necklace of the Dwarves, that he knew his parents had died. He stared at the Silmaril long with grief that death had come upon his parents so soon.
In the Silmarillion (1977), the co-author Guy Kay was tasked with coming up with an explanation for why the girdle/veil of Melian was brought down to allow dwarves back into the city to sack it. It is not clear how much of it was J.R. Tolkiens ideas and how much of it was Guy Kay's but Unfinished Tales and HoMe series attribute much of that chapter as a construction of Kays.
In the story as it appears in Of the Sacking of Doriath, she entrusted Mablung to send word to Beren at Tol Galen and gave him the Silmaril for safe-keeping. She then left Middle-earth and returned to Valinor leaving Doriath vulnerable.
As noted by Christopher Tolkien he mentions never being fully happy with having used a construction (that was not wholly of his fathers) and in hindsight and with discovery of later works of his father (which included the intent to go back and incorporate much of the elements of the earlier stories), he admits he could have retained much the elements of both accounts, with very little editorial involvement (and should have included the extended parts of the story). In the 2017 Beren and Luthien work, he has reached that goat to a certain degree.
The Dwarves of Nogrod assembled a great host and marched out of the Blue Mountains, crossing the river Gelion, and headed westward to Doriath. Crossing the Aros River, the Dwarves reached Doriath with no magical enchantments (i.e. the Girdle of Melian) or barriers to stop them. The Elven sentinels and their captains there were no match for them, and were quickly defeated; then with few losses, the Dwarves passed over the great Bridge of Menegroth, and entered the caves thus beginning the Battle of the Thousand Caves. After fierce fighting in which many on both sides were killed, they were victorious and pillaged, plundered, and destroyed at their leisure and much was taken from the Great Hall of Thingol. Then, they came to the treasury and slew Mablung before its doors and took the Nauglamir and the Silmaril.
The Dwarves left Doriath but didn't live to enjoy the fruits of their victory. At Sarn Athrad, they were ambushed by an army of Laiquendi led by Beren and his son Dior. The Dwarven host, heavily weighed-down with loot, were destroyed and the survivors that fled into the forest ran into the Ents and were killed. Both the Silmaril and Nauglamír were taken by Beren to Tol Galen. This marked the end of the first kingdom of Doriath until Dior and his wife Nimloth came to claim it ruling over the surviving Sindar, soon afterwards.