Music theory has to do with how music works, what makes it sound good, rhythm, harmony, and dynamics. Although there are numerous songs out there, they typically follow "rules" known as music theory.
Rhythm has to do with the 'pattern' a particular song follows. A rhythm has a common beat called timing. Most songs are based on a 3-beat or 4-beat timing. However, there is no rule stating that they have to have a 3- or 4-beat time.
Harmony has to do with how two or more different notes sound when played together. When several notes are played together they form a chord. Chords, like notes, have names - Cmaj, C7, Gmin7, etc. When several chords are played in a particular sequence it is called a chord progression.
Dynamics has to do with how loud or soft, fast or slow a song might be played. Some songs speed up and slow down in places. Some start loud and get soft. These dynamics add feeling to the music.
Put them all together in the right order and the music is pleasing to our ears. Just as some notes form bad sounding chords, some chord progressions don't seem to sound right. The key to a good sounding song is learning what chords, progressions, rhythms and dynamics sound good to people.