The sentences on the left are known as indirect speech, and the ones on the right are known as direct speech. This is a more general phenomenon; the matrix clause need not be a command (as in your examples), but can also be - in fact, are more commonly - statements, as I'll illustrate in the examples below.
The primary difference between the two lies in deixis, which is a pragmatic concept. In direct and indirect speech, we 'point' to the same entities, but from different angles, and therefore need different deictics.
Subtypes of deixis include person (e.g. personal pronouns), spatial (e.g. NPs denoting places with reference to the point where the speaker is standing) and temporal (e.g. tense, time with reference to the present) deixis, and all three need to be changed when transforming from direct to indirect speech and vice versa:
- Drop by tomorrow! -> I told him to drop by the next day.
- Find me a shoe! -> Mary said to find her a shoe. Who is that?
- Would you mind writing your name here? -> I asked him if he would mind writing his name there.
- I go to school by bus. -> Susan said she went to school by bus.
To illustrate the mechanism, take 'here' in the third example. 'Here' refers to a place which is near; when we remove ourselves from the speech act, that place is no longer near, so we use 'there' - point to a faraway place - instead.
A note on terminology: the word 'imperative' is usually used to refer to the syntactic, often formal mood. So for the third sentence, just calling it a 'command' would avoid confusion.