The circumstances are different from show to show. Some networks own the show outright. Some shows are produced by a studio or production company and if a network likes the show they'll pay for a number of episodes to be made. If enough people watch, the network will order more episodes.OT
Do TV studios, because they are a slowly dying business, still pay for TV shows to be made.
I don't think TV shows are a dying business. They say right now it's in it's golden era where it's not relegated to free network TV which opens the content more to which why you see movie stars doing TV now while movies are losing their luster.