Sondheim was asked which came first, the music or the lyrics. His reply? "The book."
The book tells the songwriter(s) where to put the songs and where they would likely fit. Even if it is only in outline form, they have to know what to musicalize.
Look at some shows that had songs, but no book and success is very rare. Even a smash like Mamma Mia has a so-so book that has plot points borrowed from existing plays and films. Rent "Buena Sera, Mrs. Campbell" sometime.
"If my life weren't funny, it would just be true. And that would be unacceptable."
--Carrie Fisher