Essentially there are two different types of royalties in this context, mechanical royalties and performance rights/royalties. One being the development of dvds, cds, videos, and the other being broadcasts on television or radio.
Because the owners of the show have all or most of the mechanical royalties, they can release and re-release boxed sets and season collections of programs on optical media for an exceptional amount of profit (dvd manufacturing is incredibly inexpensive, and boxed sets of popular shows usually start out around $100US). Most film composers for example, don't receive mechanical royalties on their work, which means that they receive little to often nothing on DVD's sold with their music on it.
Studios only pay out royalties if there is a stipulation in the contract that requires them to do so (which makes sense, these are business people after all). So, essentially, studios are making a small fortune on royalties from television shows, and they are able to release the show once in season by season form, then turn around and release a special edition boxed set of the entire thing, and then maybe do another run of it later, and the writers receive little to nothing for it...Writers, naturally are incensed about this because they're the ones who created the show (Note: Studios have a different definition of "created", I'm using the term very liberally).
It's essentially a license to print money for studios...except for when they are dumb enough to release things nobody wants, but that's why things like "Good Times" come out as boxed sets that start at $20-$25 and quickly drop down to $10 for a clearance sale, instead of being $100 to begin with.
Regardless, even this isn't much of a gamble because DVD authoring and production is so incredibly inexpensive now that the infrastructure has been in place for mass production for so long.
The situation in many ways is a lot more complicated than this, but that's the basic idea.