I always wondered why a show associated with CBS these days, was originally on NBC, in its original 1960s Broadcast. And why TNG, Deep Space Nine, and Voyager ended up on syndicated (for the first two) and UPN for the last.
In part because, as explained in The Next Generation's Wikipedia page:
By 1986, 20 years after the original Star Trek's debut on NBC, the franchise's longevity amazed Paramount Pictures executives. Chairman Frank Mancuso Sr. and others described it as the studio's "crown jewel", a "priceless asset" that "must not be squandered". The series was the most popular syndicated television program 17 years after cancellation
Also, as explained in another section of that same page, the traditional networks (and even the fresh upstart) did not treat the franchise with the respect its owners felt it deserved:
Despite Star Trek's proven success, NBC and ABC only offered to consider pilot scripts for the new series, and CBS offered to air a miniseries that could become a series if it did well. That the Big Three television networks treated Paramount's most appealing and valuable property as they would any other series offended the studio. Fox wanted the show to help launch the new network, but wanted it by March 1987, and would only commit to 13 episodes instead of a full season. The unsuccessful negotiations convinced the studio that it could only protect Star Trek with full control.
So instead they went another way:
Paramount increased and accelerated the show's profitability by choosing to instead broadcast it in first-run syndication on independent stations (whose numbers had more than tripled since 1980) and Big Three network affiliates. The studio offered the show to local stations for free as barter syndication. The stations sold five minutes of commercial time to local advertisers and Paramount sold the remaining seven minutes to national advertisers. Stations had to commit to purchasing reruns in the future, and only those that aired the new show could purchase the popular reruns of the Original Series.
This turned out to be a major financial coup:
By the end of the first season, Paramount reportedly received $1 million for advertising per episode, more than the roughly $800,000 fee that networks typically paid for a one-hour show; by 1992, when the budget for each episode had risen to almost $2 million, the studio earned $90 million from advertising annually from first-run episodes, with each 30-second commercial selling for $115,000 to $150,000.
WRT Voyager, that show's Wikipedia page again provides the answer:
Paramount Pictures commissioned the series following the termination of Star Trek: The Next Generation to accompany their ongoing Star Trek: Deep Space Nine. They wanted it to help launch their new network, UPN.
In addition to @BCdotweb’s excellent answer:
Star Trek began as a production of Desilu, an Independent Studio
Star Trek was developed at Desilu, the independent television studio owned by Desi Arnaz and Lucille Ball (hence the name).
As mentioned in the comments by @PaulieD, they literally shopped it around to all the networks, and NBC bought the pilot. Actually, NBC bought it after a second pilot was made, with a mostly all-new cast.
All the details of how the series started, including production memos describing the shape of the Enterprise and possible names for the “Spock” character — Spork? — are detailed in Stephen Whitfield and Gene Roddenberry’s The Making of Star Trek (ISBN 0345340191).
See also “How Lucille Ball Made Star Trek Happen”, by Devin Faraci, 2013, on Birthmoviesdeath.com.
Desilu was later acquired by “Paramount Pictures, a Gulf+Western Company” — it was probably their biggest asset, alongside reruns of I Love Lucy. Paramount is the forerunner of today’s Viacom-CBS.