There are many reasons given for why Robert gave Stannis Dragonstone, and all of them are plausible. It's possible the first two reasons I list informed Robert's decision, but the last one is definitely true according to George R.R. Martin.
As a slight- Robert clearly didn't like Stannis all that much, and the feeling was mutual. But at the same time, he also says he never cared all that much for Renly, either. So it isn't clear why he would stiff his adult brother in favor of a much younger brother he disliked slightly less (especially given Stannis' excellent job in defending Storm's End throughout the war).
Stannis and Cersei both think this is the reason why Stannis was given Dragonstone. In particular, Stannis believes that Robert blamed him for letting Viserys and Dany escape the fortress.
Practicality- Dragonstone was a hotbed of Targeryen loyalists, and their ancestral seat before Aegon's Conquest. One reason given for Stannis' appointment as Lord of Dragonstone was that it needed a strong head to watch over it. In addition, Stannis was Robert's master of ships. It makes sense that he'd be positioned at the island that has traditionally protected King's Landing from naval invasions.
This seems to be the reason Robert gave to Stannis:
I never asked for Dragonstone. I never wanted it. I took it because Robert’s enemies were here and he commanded me to root them out. I built his fleet and did his work, dutifully as a younger brother should be to an elder, as Renly should be to me.
To honor him- Believe it or not, this is the canon reason. Dragonstone was traditionally given to the Targeryen prince who would one day rule the realm. That why Rhaegar Targeryan (and Baelor in The Hedge Knight) was styled the "Prince of Dragonstone" . So by granting Stannis Dragonstone, Robert intended to designate him heir to the throne, before Joffrey came into the picture.
From the mouth of GRRM:
Stannis always resented being given Dragonstone while Renly got Storm's End, and took that as a slight... but it's not necessarily true that Robert meant it that way. The Targaryen heir apparent had always been titled Prince of Dragonstone. By making Stannis the Lord of Dragonstone, Robert affirmed his brother's status as heir (which he was, until Joff's birth a few years later). Robert could just as lawfully retained both castles for his sons, and made Joffrey the Prince of Dragonstone and Tommen the Lord of Storm's End. Giving them to his brothers instead was another instance of his great, but rather careless, generosity.