While many dogs may swallow socks because of boredom, or as part of a game, on a more serious note, some dogs may do so as a form of resource guarding.
In this case, the dog perceives the sock as a valuable item, perhaps as valuable as bones, toys and other items they are particularly eager of having.