I had a spanish teacher in high school that told our class that the reason Spaniards speak with a lisp in their accent is due to the fact that some Spanish king had a lisp. Apparently, everyone started speaking with a lisp, so they didn't make him feel bad (or something along those lines). Is this true? How could a whole population suddenly change their accents to this extent? (I really hope this isn't some random thing she made up, or I'm going to feel really dumb...)
Pardon my Spanish, but no, that is 100% carajo. It's also not something your teacher made up; the myth has been popular for a long time, especially online.
While prestige is a factor in language change, this is not how it works. People do not immitate the speech of one person, only groups of people, for it to catch on in a community, and furthermore if they immitated the speech of a lisping king in such a manner, it would certainly not be out of reverence and certainly not be welcomed. We have no examples of language changing in this way.
Linguists do, however, completely understand every minute sound change that brings Latin into Medieval Castilian and finally into Modern Spanish, including the origin of the sibilant system. And we know for a fact that [θ] (modern orthography: z as in cabeza) has a completely different origin from [s] (modern orthography s as in soledad).
What's more, if Spaniards were actually lisping, they wouldn't be able to say both sounds in the same sentence as they do: la cena es deliciosa [la θena es deliθiosa]. This isn't lisping. Are English speakers lisping when they say thistle [θisl]? No. They're lisping when they say [θiθl].
The origin of [θ] in Spanish begins with Latin [k] and [t]. Everywhere [k] and [t] appeared before front vowels, or the palatal glide [j], they were changed to [ts] (really [k] was changed to [ʧ] and then to [ts], but we can skip a step). Latin capita was capitia in Hispanic Latin, the Latin spoken in Iberia, for the purposes of these examples. So first we have [kapita] > [kapetea] > [kapetja], due to some vowel mergers and hiatus resolution. Then because [t] occurs before [j] here, the sound change [t] > [ts] applies: [kapetsa] in medieval Castilian. Because [ts] occurs between two vowels, it also changes voicing - but it will change back before we're through, so it's not important (the same thing happens to the [p]): [kapetsa] > [kaβedza]. We'll pause here.
Now three things happen to this phoneme between Medieval Castilian and Modern Spanish, and they happen in a specific order. The first is deaffrication, changing an affricate (two sounds together) like [ts] or [dz] into just one sound. In Castilian this sound was ş and it's voiced pair z̧, which are laminal (also called dorsal) sibilants. At this point in the language the pair of laminal sibilants contrasted with the pair of apical sibilants (the s in deliciosa). Basque has this same contrast today, but it has been lost in Spanish. Anyway the important thing here is that they're still two distinct sounds that would not sound the same to any Spaniard. So [bratso] became [braşo], and [kaβedza] became [kaβez̧a].
The second thing that happens is voiced sibilants devoice. This is believed to have began in the northern region of Castile in the mid-16th century and expanded as people moved to the new capital of Madrid. Every instance of [z] became [s], every instance of [z̧] became [ş], every instance of [ʒ] became [ʃ]. So [kaβez̧a] becomes [kaβeşa].
The third thing that happens is the laminal sibilant (now there's only one, no pair) [ş] becomes fronted, or what we call maximally anterior, meaning the tip of the tongue goes as far forward as it can. This may have been due to a theory sometimes called 'functional distribution', where sounds in a language's phonemic inventory want to be maximally distinct from each other, and so some sounds move back in the mouth and some move forward, but whatever the reason, that doesn't change the data, and it certainly wasn't because of a lisping king (that the internet legends cannot agree on who that was, either, incidentally, because they made it up).
What maximally-anterior means in the case of a sibilant is it becomes an interdental fricative, so here [ş] > [θ], and we finally have the Modern Spanish form [kaβeθa] or cabeza as it is written (note how the z is a holdover from medieval orthography from back when [θ] was a laminal sibilant, and voiced. And of course it isn't just this word, but anywhere the sound occurred. So el Çid underwent: [kid] > [tsid] > [şid] > [θid]. And here note the c, another relic of medieval orthography.
And then in the Americas the sounds [θ] and [s] merged into [s], and the history was obscured even more.
Source for examples: Pharies, David A. (2007) A Brief History of the Spanish Language. University of Chicago Press.