A Hebrew servant who refuses to accept his freedom is to be brought to the judges (the Hebrew literally means, “bring him to God”, but “God” sometimes means the judges: see Deut. 1:17 and Psalm 82:1) and stood beside the doorpost of the city gate and an awl used to pierce through his right ear into the door.
Not a pleasant notion, but it is meant as a stern warning that no-one should opt for servitude rather than freedom.
Why is the doorpost part of the procedure? Because the doorpost was a major symbol of the redemption from Egypt (Ex. 12).
The doorpost which represents freedom here witnesses the disgrace of a man who rejected freedom.
Why was the ear pierced? Because the ear heard God say, “To Me (but not to human beings) are the Children of Israel servants” (Lev. 25:55), and this man apparently failed to hear the message.