Dar is an -ar verb, but in this tense it behaves like an -er or -ir verb. It is the only verb in the language with this particular peculiarity.
Me dio · Me lo dio · Nos lo dio · No nos lo dio · Te lo di
Spanish does not like the sound of two of these little l-words side by side. Where you would have le lo, the first turns into se.
le lo / les lo / le los → se lo, se los
This is purely about sound, not grammar. It changes no meaning, and it has nothing to do with the se that means himself.
Se lo di · Se los di · Se lo vendí · Se lo envió
Which does mean se lo di covers a lot of ground: I gave it to him, to her, to you formally, to them, to you guys.
Because of all that ambiguity, you often want to clarify. The method is simple and, for a learner, generous: you keep the whole sentence and add the clarification on the end.
Se lo vendí a él.
You do not drop the le or se when you add a él. You repeat. So there is no need to restructure the sentence, and the base stays untouched.
Le di algo a él · Le di algo a ella · Le di algo a usted · Se los vendí a ella · Se las vendí a ellos · Él se lo envió a ella
This a is special because it is flexible: it can stand in for other prepositions too. Me lo compra a mí can be from me or for me. That is probably why it is the one that repeats.
Asked for I gave you it, the student's mind jumps to you gave. The remedy is the one from the very beginning of the course.
A useful way to see these sentences: there is a base structure, and you clarify around it without disturbing it.
se lo envió · él se lo envió · se lo envió a ella · él se lo envió a ella
No se lo envió a ustedes todavía · No sé si se lo envié
The teacher closes with this explicitly, about these very specific details of the language.