It came from the old Flemish word 'dok', meaning a rabbit-hutch or chicken-coop. In English, it first appeared as criminals' slang in the 16th century for the accused's place. This was presumably based on the similarity in appearance of the farmyard/courtroom structures...and also perhaps on the grounds that one might be taken from it and put to death!