There are some conflicts about where exactly the term top 40 originated. However, most do agree it is related to jukeboxes of the 1950's which held 40 records. These would typically be the 40 most popular songs in the location owning the jukebox. It was not long before the concept of top 40 evolved into a radio format playing the most popular songs of the day.
On July 4, 1970, Casey Kasem and Don Bustany debuted the radio countdown show American Top 40. This hugely popular weekly program cemented the concept of top 40 int he public consciousness. To this day mainstream pop radio is often referred to simply as top 40 radio.
Read more details on the evolution of top 40.