When we think of great classical music we think of symphonies etc, and that’s still considered a marker of class and sophistication, but there was lots of popular folk music that existed throughout that time period as well.
Do we know what the great composers thought of this music? Did they enjoy a ribald tune like the rest of us? Did they look down their noses at this low form of entertainment? Did they recognize any compositional merit to these tunes?
If it's ribald tunes you want, Mozart's your man (and yes, Lech mich im Arsch means exactly what you think it means)!
But the answer to your question is that classical music and popular music have always been inextricably linked. For one, a tune is a tune. The catchiest ones that classical composers wrote always ended up making it out onto the streets. One of the most famous examples of this is Verdi's aria La Donna è Mobile from Rigoletto. He withheld the aria from rehearsals, and even from the tenor who was singing it, until very close to the performance. He then made the tenor swear that he would only practice it in secret, and not hum or sing it around anyone until the first performance.
Why would he do this? Because he knew that a tune like that would spread quickly in Venice, and he wanted it to have the right impact. If the aria got out ahead of time, everyone would be singing and humming the best tune in the whole opera before they even saw the show!
Verdi wasn't the only one who saw his music taken up into the streets. Mozart told this story about his 11th Serenade in a letter to his father:
At 11 o’clock at night I was serenaded by two clarinets, two horns, and two bassoons playing my own music: I had written it for St. Theresa’s Day for Frau von Hickel’s sister, or rather the sister-in-law of Herr von Hickel, the court painter, at whose house it was performed for the first time. The six gentlemen who executed it are poor beggars who play together quite nicely all the same, especially the first clarinetist and the two horn players. And so these musicians had the front gate opened for them, and when they had formed up in the yard, they gave me, just as I was about to undress for bed, the most delightful surprise in the world with the opening E-flat chord!
The truth is that "popular" and "classical" music often went hand-in-hand. Operas were a constant source of popular melodies, and the best arias from a popular one were likely to make it out of the opera houses and into popular consciousness. Composers also wrote a lot of populist music for festive occasions. I wrote about one such piece, Tchaikovsky's 1812 Overture, in an answer on this sub. The fact that it has become such a popular piece isn't really an accident; it was always made to be a catchy, bombastic piece that appealed to the masses. The Serenade that Mozart describes above was written for a small wind ensemble, which was a very popular kind of group to have playing at a party or out on the streets. As you can see from that anecdote, music written for those types of groups would have been perfect for popular consumption and performance.
On the flip side, composers have found a lot of great material in popular melodies and songs. One of the most famous is Mozart's variations on a French song called Ah, vous dirai-je maman, a song we know of as "Twinkle, Twinkle, Little Star." It's a brilliant little piece to listen to, because using such a familiar melody as the base means that it's easy to hear all of the variations and compositional tricks that Mozart uses. It's though that he wrote this as an exercise for his piano students; again, it's a way to get the students thinking about techniques while being able to play a melody they are already familiar with.
The "theme and variations" concept was also very popular among virutosi who gave concerts to packed-in crowds. Taking a well-known melody and putting your own spin on it is a time-honored tradition (just look at all the cover version YouTube channels there are!), and classical musicians were no exception. You can see just how effective this is as a showy technique in Paganini's version of the popular aria "Nel Cuor Piu Non Mi Sento." You can listen to a fairly straightforward version of the aria here and then Paganini's version. There's enough of the tune to catch your ear and use as a grounding to showcase Paganini's explosive talent.
It isn't all showpieces and flash, though. Composers have also used popular music in more serious works, especially for a particular effect. The aforementioned 1812 Overture uses La Marseillaise to signify the French army, while a Russian Orthodox hymn is used for the Russians. Brahms' Academic Festival Overture was written as a tribute to a university that was giving him an honorary degree, and features the melodies of drinking songs that were popular among students. Other pieces like Dvorak's Slavonic Dances aren't straight-up arrangements or borrowings of popular melodies themselves but are inspired by popular and folk music and meant to evoke the same feeling.
Those Slavonic Dances are also a great example of yet another intersection between "popular" and "classical." They were originally written as piano pieces and sold as sheet music to amateur musicians, making Dvorak a very rich man. Remember, back before the advent of recording technology any music you heard had to be made by someone within earshot. Not everyone was a virtuoso, so music for all abilities was in demand. A couple hundred years earlier than Dvorak, Telemann also made a fair bit of money with a wide range of relatively easy music written with the amateur in mind.
It's important to remember that the concept of "classical composer" as a separate, ivory tower-style type of composer is an artificial one that composers like Mozart wouldn't necessarily have recognized. From the amateur music of Telemann's day to the film and video game scores of today, there are plenty of intersections between "classical" and "popular."