Technically, the sentence is missing a comma:
Tu l'as acheté où, ce pantalon ?
To parse it, better to first ignore the trailing part that is optional. That reads:
Tu l'as acheté où ? or the variants où tu l'as acheté ? and où l'as-tu acheté ? (formal)
This clearly translates to
Where did you buy it?
But the person speaking wants to make sure you know what the pronoun le refers to, so (s)he states it clearly either at the beginning or at the end of the sentence. That gives:
Ce pantalon, tu l'as acheté où ?
or
Tu l'as acheté où, ce pantalon ?
Finally, Tu as acheté où ce pantalon ? is possible although not very common but you can certainly hear:
Où tu as acheté ce pantalon ? (common) also Où t'as acheté...
Tu as acheté ce pantalon où ? (common) also T'as acheté...
Où as-tu acheté ce pantalon ? (formal)
T'as acheté où ce pantalon ? (colloquial)
They all means the same thing as above.