Understand how musicals work. Most linear musicals are written in similar stages to what we would consider to be Joseph Campbell's Hero's Journey guide and the whole idea of the monomyth. This is what Julian Woolford explains in his book How Musicals Work: and How To Write Your Own (particularly the chapter Song Spotting). But don't feel like you need to stick to a structure, you soon learn in that book that even the musicals that fit into the Hero's Journey the best do not fit into every stage of the journey. But definitely learn about why things like the 'I Want' song are important and why you cannot have musicals without them, there's the Howard Ashman quote from Waking Sleeping Beauty which goes into why specifically the 'I Want' song is important, or take a leaf out of Starkid's book and understand why it's important through this way. Either way, the songs have to have a purpose. You can't just have a song stop a show for no reason. They have to push the song on or explain something about who the character is or how they feel.
Now you need to know the other very important formula to musical theatre to make everything come together: "When the emotion becomes too strong for speech, you sing; when it becomes too strong for song, you dance." (this source). If you want to see a seemless performance of this, watch someone perform the entirety of 'The Music and The Mirror' with the dialogue included, from A Chorus Line and compare it to the song and the scene they replaced it with in the movie, 'Let Me Dance For You'. The reason why 'The Music and The Mirror' is iconic and works so well, is because it builds the tension up with speech, to singing, until there is nothing Cassie can do but dance her emotions out. She doesn't even do a final chorus at the end like in 'Let Me Dance for You' because that would be reverting backwards, that would suggesting she has something new to say when really she doesn't. You know this video here that makes fun of characters in musicals transitioning from speaking to singing? There's a reason that's a common trope.
Popular alternatives to
How Musicals Work: And How ...