I mostly agree with Darrel Hoffman's answer that points out the historical basis for repeats often involved variation/improvisation in those repeats. We have plenty of historical examples of composers writing out such repetitions with variation, and composers like C.P.E. Bach who specifically wrote collections of simpler pieces called "Sonatas with Varied Reprises" designed to teach beginning performers who to introduce variation and ornamentation when playing repeats.
Originally with soloists and small instrumental ensembles especially prior to ~1800, a better comparison might be with a jazz ensemble today, where a "repetition" might follow the lead sheet or arrangement but introduce some variation. And of course repetition is very common to most popular styles of music.
That said, I wanted to highlight another critical aspect that surprisingly seems missing from other answers so far: repetition teaches the music to the listener.
Today, we often view "classical" music as this artistic contemplative music that we might sit around and analyze for hours, or which we might play recordings of over and over. We might even sit down with friends and compare a number of different recordings of the same piece, contemplating their subtleties.
This is a great way to listen, but it's also very ahistorical. In the 18th century, for example, when you had these increasingly long sonatas and symphonies and concertos, performance was a luxury. You might only get to hear a large ensemble piece of music once in your lifetime actually performed. And while music publishing was growing a lot in the 18th century, the heyday of keyboard arrangements to study and learn large-scale pieces like symphonies by yourself at home was more of a 19th century phenomenon.
So, given that context, now imagine you're getting to hear a new 10-minute orchestral movement for the only time you may ever hear it performed. As a listener, how the heck do you know what's going on? What do you focus on? Did you catch the main theme? Did you get distracted and forget it because the oboe player made a mistake the first time? Did you space out for a minute and miss that amazing descending bass pattern with crescendo that led into the next main theme?
If you're playing a giant sonata form movement spanning many minutes, it can help to simply hear the music again. As a listener, it helps you get oriented to the music, to catch the main themes, to understand how they connect and lead into each other.
Just to pick apart the traditional sonata form as an example, the second main section is called the "development," a term we use often because it references back to earlier themes and "develops" them. How will you as a first-time listener even catch those references to earlier themes unless you know them? Often the development is about creating drama and subverting earlier expectations too. Again, if you weren't paying attention the first time around, you may not catch the way the drama unfolds when that theme doesn't go where it's expected to (based on what it did in the exposition). So, maybe as a composer you should repeat that exposition to make sure the listener really knows what the themes are first. (Note that even as later repeats fell away in the 19th century, that first repetition of the exposition was often kept for this reason.)
Essentially, if you're in a culture without recordings, performances (particularly of larger ensemble pieces) may be rare. You want to give the listener as much information as possible to try to follow what's going on. Repetitions are simply an essential tool for doing so, particularly as the works grew longer in the Classical and early Romantic periods.
Later in the Romantic period, of course, composers often took a different perspective. They more frequently omitted repeats and instead might focus on an idea of continuously developing themes throughout a movement in a more integrated and constantly flowing way. The "drama" of a sonata form in the Classical period was to some extent created around expectations of structure. So, you needed to teach listeners that structure so that they might retain enough to sense when it deviated or was modified to deny an expectation in a dramatic fashion.
The more precise structural expectations of that earlier music gave way gradually to a more free-flowing and continuously developing form for many composers. Drama was articulated through a greater variety of timbres/instrumentation in larger orchestras, wider dynamic ranges, and overall a more "episodic" structure. Think of listening to Wagner and how recurring Leitmotifs help to give meaning to your experience and allow a listener something to latch on to while experiencing the music. That's similar to a Mozart theme in a very broad sense, but now it can just occur in different forms and be developed within a constantly changing sound environment. Exact repetition is no longer required or even desirable because the structural expectations are different. The composer gives listeners something different -- a new kind of "grammar" of musical elements -- to keep track of while experiencing a piece for the first time.
Also, as I noted above, the 19th century saw a huge increase in transcriptions and study scores sold to the public, so they had time to "digest" the music perhaps outside of a single performance. That too may have led some composers to feel more free to develop longer and less rigid structures, as they no longer had to essentially "teach listeners" the themes and the other stylistic vocabulary of the piece in real time, at least for "educated" listeners. The concept of music analysis in the modern sense really began. Whereas in earlier periods, music theory was mostly compositional and performative (in that it could aid in some aspects of performance, like improvisation, continuo-playing, etc.), not primarily analytical or about listening.
In sum, repetition is an essential concept to orient new listeners to a piece of music. It also helps to set up expectations for listeners -- e.g., that theme A will flow to theme B, or that harmony X will resolve to Y. If you look at psychological responses to music, familiarity can help to create emotional response: you come to enjoy the fact that A goes to B and X goes to Y. It's familiar and comforting. Particularly if those resolutions happen in a dramatic fashion. But then, it also gives the composer an ability to surprise you: suddenly A goes to C! Oh wow! That's shocking! Now your ears perk up -- this is new! What will happen next?
None of that kind of formal drama can happen without repetition creating expectations and then either fulfilling them or subverting them.
Such expectations happen on many levels in music -- in individual phrases or even on a chord-by-chord level. It's why many classic small forms for melodies do things like AABA song form. It's comforting to get to "know" the first phrase A, because then B can sound like a contrast, and then comforting to feel the familiar A return again. Sonata form is doing the exact same thing on a much larger scale when it repeats an exposition.