We're the elves happy after getting the clothes
Answers
You put down one of those big laundry things on wheels under a chute.
You order your house elves that they’re not to touch the clothes coming down the chute, nor the clothes in the wheeled basket thing.
You order them that they’re only to use their magic to clean, fold, and put away the clothes. IE, they never touch the clothes while cleaning them but use levitation and other magic instead.
You order them that they are not to touch discarded clothes in the house, not even those thrown at them by accident or purposefully by children (who don’t know not to do that).
Trust to the fact that most house elves don’t want to be free, and thus will do all they can to prevent it.
This way, the combo of A. Dobby wanting to be free, and B. The presumed fact that Mr. Malfoy never had reason to order Dobby not to touch discarded clothes when they were outside of the home (because how likely is it for that to happen outside of the home, honestly?), and C. Them not being in anyone else’s house at the time either, and D. Mr. Malfoy being too distracted to realize that it wasn’t safe to discard the sock there in Hogwart’s, means that Dobby being freed that way was probably a rare fluke indeed.
Now, before you ask, yes the same orders probably are given to the Hogwarts house elves, but since Dobby wasn’t working for Hogwarts at the time, and Hogwarts is a public place, it likely didn’t count.
That said, if that scene had taken place in one of the dormitories, it probably would not have freed Dobby, since dormitories would be considered semi-private spaces and definitely domestic spaces, where the orders would be expected to be obeyed. But in the rest of the castle, not so much.
What’s more, intention matters in magic. The house elves of Hogwarts wouldn’t touch Hermione’s knobbly hats and stuff because she was intending them as gifts. Had they just been discarded, the elves could have treated them like any other clothing, but offered as a gift, they couldn’t risk even levitating them away in case that activated the magic that freed them. So since Dobby didn’t care and was technically still free, they made him do it instead.
And with that in mind, it could be that if Mr. Malfoy had tossed any old sock at Dobby, that it wouldn’t have done anything, but since Harry was intending the sock to free Dobby, maybe the fact that Mr. Malfoy passed it along to Dobby was interpreted by the magic as Mr. Malfoy agreeing with Harry’s intention. Since he was distracted and thus had no contrary intention at the time, it was taken as assent, and Dobby was freed.
I hope you are understand my solution