The answer is, they don't always fit together. The lyrics and the rhythm fit together seamlessly in the best songs, so that it seems impossible to separate them. However, in weaker songs, they fight each other. Too many words are jammed in, or the singer has to hold notes and even distort words to make them come out. Also, the sound of a word often fights the speed of the rhythm. Songwriters work very hard to get the words and rhythm to fit together. It's a mix of feel—this feels like a fast paced section, etc.—and conscious choice, as when, say, words with long, open vowels are placed in sections calling for an extended note.
When a lyricist is creating words for a song, he/she listens carefully to the meter or beat of the song and then chooses words that fit with the pattern. If the music is written in 4:4 timing, then there are four beats per measure with the quarter note getting the beat. That means that if the lyricist wants each beat to be one syllable, then he will choose four syllables per measure. If a word that he/she chooses to use has more than one syllable, he can substitute two eighth notes in place of one quarter note to fit the beat. Instead of "1, 2, 3, 4", you would get "1 and 2, 3, 4". It's still 4:4 time, but it has five syllables. This is also how poetic meter works. Each specific format has so many poetic "feet" per line, and there are many types of poetic "feet" to choose from, depending on which syllable gets the accent/beat. Iambic pentameter has five "iambs" per line; an iamb is a two syllable pattern that is accented on the second syllable. The name Christine is an iamb because the stress is on the second syllable. If you repeated her name five times, that would give you the sound of iambic pentameter. Poets and songwriters who have selected their melodies then work carefully to choose words that fit the pattern in order to make the song flow.