The country began with a name that was a list. When it was formed on 1 December 1918, after the First World War, it was the Kingdom of Serbs, Croats and Slovenes.
The idea of a single South Slavic state was much older. Wikipedia traces it to the late 17th century and to the Illyrian Movement of the 19th century. English already had the word Yugoslav by 1853, according to Etymonline, for the southern Slavic peoples as a group.
The name is a compound. Jug means "south" in Serbo-Croatian, from Old Church Slavonic jugu, which could also mean "south wind" or "noon." The second half is the word for Slavs. Together they make "land of the South Slavs."
The renaming was political. On 6 January 1929 King Alexander I dissolved the constitution and banned national political parties. Later that year, on 3 October by most accounts, the state became the Kingdom of Yugoslavia. Three national names were replaced by one shared one.
The name survived the end of the monarchy. On 29 November 1945 the country became the Federal People's Republic of Yugoslavia. In 1963 it became the Socialist Federal Republic of Yugoslavia. As the socialist federation broke apart, a new Federal Republic of Yugoslavia was formed on 27 April 1992. In 2003 that state was renamed Serbia and Montenegro, and Yugoslavia vanished from the map.
The word Slav has its own tangled history. Etymonline traces it through Byzantine Greek Sklabos to a Proto-Slavic word probably related to slovo, "word, speech." Citing the Slavic scholar Max Vasmer, it rejects the popular link to slava, "glory." The same Medieval Latin Sclavus also gave English the word slave. Etymonline explains that so many Slavs were sold into slavery by conquering peoples that the ethnic name came to mean an enslaved person.
So the country's name celebrated a people whose ethnic name had once, in other languages, come to mean a slave.