Abandonment of Dragonstone

The Abandonment of Dragonstone was an event during the War of the Five Kings, leading into the first action of Daenerys Targaryen's invasion of Westeros when she landed on Dragonstone.

Season 4
Stannis Baratheon left his main base at Dragonstone with his entire army to save the Night's Watch at the Battle of Castle Black.

Stannis totally abandoned the castle, taking every last man with him to aid his campaign in the North.

Meanwhile, House Lannister in King's Landing made no attempt to capture the now totally abandoned castle, for the next three full years during the reign of King Tommen Baratheon. The Lannisters were aware that the castle was utterly undefended - though Dragonstone is a vitally important island fortress commanding the naval approach to the capital city through Blackwater Bay.

Season 7
After Tommen's death and Cersei's seizure of power, Cersei asked Jaime Lannister where Daenerys Targaryen was most likely to land first when she began her invasion of Westeros. Jaime correctly assessed that she would probably try to take Dragonstone first, as it has good deep water ports for her fleet, Daenerys was born there, and Stannis left the castle abandoned so she wouldn't face any resistance. Neither Jaime nor Cersei suggest rushing Lannister soldiers to the abandoned castle to defend it from Daenerys's landing.

When Euron Greyjoy came to King's Landing with his fleet to propose a marriage-alliance with now-Ruling Queen Cersei Lannister, he made no attempt to capture the empty fortress, despite passing it twice as he entered then left Blackwater Bay.

Ultimately, Daenerys lands her fleet at Dragonstone without opposition. She and her followers enter Dragonstone castle, and she assumes control, to begin planning her invasion of the rest of Westeros.

In the books
Daenerys Targaryen hasn't returned to Westeros yet as of the most recent book in the A Song of Ice and Fire series. The events regarding Dragonstone are as followed:

Background
Before travelling to the North, Stannis leaves skeletal garrisons in Dragonstone and in Storm's End, under the command of Ser Rolland Storm and Ser Gilbert Farring respectively.

While Stannis stays in the North, he barely speaks about Dragonstone. After hearing Samwell Tarly's story about destroying the Other with a dragonglass dagger, he mentions there is a lot of dragonglass in Dragonstone, and sends orders to Ser Rollam to mine the precious material for making weapons against the Others. It is unknown whether Ser Rolland received the order and fulfilled it.

Shortly after Cersei is appointed to the Queen Regent, she decides to conquer both Stannis's castles, in order to secure Tommen's hold upon the Iron Throne. She sends to Dragonstone 2,000 Lannister soldiers and the Redwyne fleet under the command of Lord Paxter Redwyne, and sends Mace Tyrell to Storm's End.

The siege
Lord Paxter, a veteran military commander, decides against launching an open assault, since it may result in unnecessary casualties; instead, he chooses a slower but safer tactic - laying a siege to the castle, in order to starve the besieged into submission (what may take at least six months). He also orders to dig a tunnel underneath the castle walls. In the meantime, Mace Tyrell besieges Storm's End.

In contrast to Riverrun, Cersei is in no hurry to take either of Stannis's castles, and does not urge the besiegers to act faster.

Loras Tyrell takes command
Shortly after Euron Greyjoy is crowned, he launches a military campaign against the Reach, cunningly taking advantage of the fact that the Redwyne fleet is away. The first stage in his plan is performed successfully: hundred of the ironborn longships, including the Iron fleet, capture the Shield Islands. Euron plans to sail east, but in view of his subordinates' objections, he changes his plans: he orders Victarion to take the Iron fleet to the Slaver's Bay and bring Daenerys, whom Euron wants to wed. In the meantime, Euron continues with his campaign against the Reach. He does not give orders to build even one additional ship (let alone 1,000), because he still has hundreds of ships at his disposal, sufficiently for raiding the Reach.

The Small Council receives reports that 1,000 ships raided the Shield Islands. Obviously the reports are exaggerated (500 is closer to the actual number of the raiding ships). Margaery and Loras  urge Cersei to give Lord Paxter orders to send the Redwyne fleet back; that would have been the logical reaction, to eliminate the ironborn threat while it is still in its initial stage. Cersei, who secretly gloat over the Tyrells' distress, fails to estimate the danger that the ironborn's invasion pose to not only to the Reach, but to the entire realm (what Sam Tarly figures very quickly).

Lord Aurane Waters objects to the Tyrells' demand, pointing out that the presence of the Redwyne fleet is essential to maintain the sieges of Dragonstone and Storm's End. Cersei agrees with him, stating that Dragonstone and Storm's End are much more important than "those rocks", and that the Tyrells must take care of the problem themselves. Loras explains that his brothers  Willas and Garlan  can mass 20,000 soldiers within a month, but that will not do any good without watercrafts that can fight the ironborn's longships. Cersei insists that the Redwyne fleet will be released only after Dragonstone falls.

Loras, fearing for the safety of the residents of the Reach, asks Cersei to give him the command over the forces that besiege Dragonstone, declaring that he will take the castle within two weeks, even if he has to take it apart with his bare hands. Cersei is surprised and delighted at Loras's offer, thinking (incorrectly) it is a win-win situation: if Loras succeeds, Stannis will suffer a grievous blow, and the Redwyne fleet can sail off to meet the ironborn; if Loras fails, he will be blamed and disgraced. As a "bonus", Cersei hopes Loras will get himself killed due to his rash nature, what will cause a lot of sorrow to his sister and grandmother. No one could blame Cersei, because Loras has volunteered willingly in public for that mission. As happens with each of Cersei's schemes, this one goes wrong too.

Loras sails to Dragonstone and takes the command. First he offers the castellan of Dragonstone to settle the siege between them in single combat, but Ser Rolland refuses. Loras orders to assualt the castle. As the ram breaks the castle gates, Loras is the first to invade. He fights valiantly, even after being shot by two arrows and suffering a mace blow that broke some of his ribs. The defenders fall back to an inner keep once the curtain wall is taken. Loras leads the attack there as well, but then he is doused with boiling oil.

Aftermath
Dragonstone has been taken, but it proves to be a Phyrric victory: Loras's rashness has turned what could have been a bloodless victory into a slaughter. About one thousand men are killed, most of them are Lannister soldiers, the best and the bravest knights and young lords.

Morever, Euron has successfully completed the second stage in his campaign: the capture of Shield Islands has opened the Mander to the ironborn's raiding ships, and they have captured the Arbor and its neighboring islands, turning them into bases for further raiding. They even pose a serious threat to Oldtown. A galley captain describes the situation to Sam, emphasizing that there is little they can do without the Redwyne fleet. He comments bitterly "the best we can do is guard the Sound and wait for the bitch queen in King's Landing to let Lord Paxter off his leash". Sam muses fearfully "if King's Landing loses Oldtown and the Arbor, the whole realm will fall to pieces" (a very accurate estimation, which Cersei fails to perceive).

Cersei, however, is not concerned about the above "minorities". She is content that the last direct threat to King's Landing has been removed, that Stannis's already failing cause has suffered severe damage. She is also very pleased to hear that Loras is near death. She finally - perhaps too late - orders Lord Paxter to sail the Redwyne fleet back to the Reach and drive the ironborn away, then goes to tell Margaery and her cousins the bad news. Although Cersei sounds sympathetic, Margaery sees through her pretence. That put a strain on the Lannister-Tyrell alliance, though it is still intact.

Mace Tyrell reports the Small Council that Loras's men have searched the castle and the whole island for treasures, mainly for dragon eggs, but found nothing. Kevan thinks it is a waste of time, for Stannis had years to find any treasure that the Targaryens left behind. It is not mentioned in the novels what has become of Ser Rolland and his men, whether they were captured alive or killed.

It is unknown whether Stannis has been informed about the fall of Dragonstone. He cannot do anything about that anyway, since he currently has much more urgent matter to deal with - the imminent Battle of Winterfell, which has not begun yet in the novels.

Although it is not mentioned explicitly, it can be assumed Dragonstone has been garrisoned by Lannister troops.

Books vs TV series

 * The TV series stated in the Season 7 premiere that when Stannis left with his army for the Wall, at the end of Season 4, he left Dragonstone completely abandoned, and that it remained abandoned up until Season 7 - three years later in the storyline - this is absurd, and has no precedent in the novels whatsoever. There is no reason why the Lannisters wouldn't try to capture the abandoned castle. When Daenerys arrives the castle is indeed abandoned, she faces no resistance, and she pulls down an old Stannis banner which no one has removed since he left.
 * In the books, Stannis took most of his army by ship to the Wall for the Battle of Castle Black, but he left a small skeleton force garrison behind - because Stannis hopes to eventually retake all of the Seven Kingdoms, and it wouldn't make sense to voluntarily abandon the defense of one of the strongest castles in Westeros. Dragonstone was constructed with lost Valyrian architectural techniques and is defensively quite formidable, so even a token defensive force can hold it against large armies.
 * The TV series omitted the taking of Dragonstone by Loras, and just had him burn to death in the Destruction of the Great Sept of Baelor (in either version, he apparently burns to death - though there is some slim chance he might in fact survive in the books).
 * Even if Stannis felt he needed to take every man he had to the Wall to focus on the campaign there...there is no plausible reason that the Lannisters would simply leave it abandoned for three years and make no attempt to retake an empty castle. Particularly because Dragonstone directly controls the sea approaches to King's Landing, across the Gullet at the entrance of Blackwater Bay. In the second novel, Stannis controls most of the former Royal Fleet, so his possession of Dragonstone allows him to enforce a naval blockade on the capital - which combined with the Riverlands and Reach no longer sending food shipments, leads to food riots).
 * This has zero precedent at any point in the history of Westeros: even if Dragonstone doesn't control the sea approach to the capital city - which it does - but if it were a more isolated castle like Storm's End or The Eyrie, no one in the history of Westeros would make no attempt to occupy a totally abandoned castle...no attempt in three years of story time.
 * Note that Theon Greyjoy managed to take and briefly hold Winterfell with a force of only 20 men. In the books, even a force of a mere 300 men can hold Dragonstone against armies in the thousands.
 * Even within the Season 7 premiere, Jaime himself observes that Stannis abandoned the castle, the Lannisters are aware of this, it is relatively nearby, and he says that it's the most likely target for Daenerys Targaryen's initial landing...yet he doesn't make any attempt to suggest that they should rush even a small force of Lannister soldiers to the castle so they can defend it against her attack. Even if they hope to defeat Daenerys, they would eventually have to retake Dragonstone castle, losing thousands of men in the process, when they could have just sent a hundred or so guards there ahead of time.
 * 701 map dragonstone.png on the large floor map.]]Euron Greyjoy's fleet had to directly pass abandoned Dragonstone, both coming and going to King's Landing. This is also blatantly obvious given that Jaime is standing on a large map at the time, visibly showing that any ship approaching King's Landing has to pass Dragonstone. Yet the TV show presents that Euron wouldn't think to capture the island, perhaps as a gift for Cersei.
 * Even if the storylines are out of synch, and Daenerys lands on Dragonstone before Euron arrives...then Daenerys's fleets would be based at Dragonstone, and attempt to stop Euron's fleet from reaching King's Landing. As presented by the episode, Daenerys simply hadn't reached Dragonstone yet, and Euron ignored capturing one of the strongest castles in Westeros even though it was empty.
 * Euron's fleet would have to sail past the Tyrells' home fleets to get all the way to King's Landing. This is comparable to when, in Season 4, the TV show had Yara Greyjoy circumnavigate the entire continent of Westeros, to sail from the Iron Islands around to The Dreadfort on the northeast side (the equivalent distance of sailing from Peru to Venezuela, the long way by sailing south around Argentina). Yara could plausibly have made a portage at the Neck, as Moat Cailin was held by the ironborn at the time, but that's just fan theorization). Even Yara could plausibly slip past enemy fleets as one ship - Euron's large fleet would have been blocked.
 * The TV show could, plausibly, have just said that Euron reached King's Landing by land, or on one ship, but apparently it wanted the big visual of Euron sailing a large fleet into King's Landing - without considering why Euron wouldn't split off a few ships to take Dragonstone.
 * Ultimately, even if Euron's arrival isn't considered, there is no plausible reason why the Lannisters wouldn't retake an empty Dragonstone castle in three years. Or even send a few fishing boats' worth of men to take it. The TV series cut out Loras's major subplot on Dragonstone and didn't want to expend more time explaining what happened to it. The TV writers didn't even want to expend time explaining in dialogue something like that off-screen, without Loras, the Lannisters retook the island from a token defensive force left by Stannis, but then the Lannister forces holding Dragonstone were overwhelmed by Daenerys's massive army when taken by surprise. This doesn't particularly affect long-running storylines that will come after this now that Daenerys holds Dragonstone.
 * The fate of the Bald Dragonstone servant remains unknown. He may have simply abandoned the castle as well, rather than hold it against the Lannisters - or, he may have correctly anticipated that in defiance of all historical precedent, the Lannisers would make no attempt to capture an abandoned castle.