How does ‘三神不挂二神’ come to mean 'unconcentrated' in this sentence?
首先，这是一个方言用语（很可能是四川一带某地的方言），并不是汉语常用的规范用语，但用在这部小说里是正确的，反映出了人物所处的地域，正确地体现了人物的性格特征。

“三神不挂二神”，意思的确是“精神不集中，不安心，不专注”，神指的是“精神”，比如“心神不定”，“神智恍惚”等等。

其实“三神不挂二神”和汉语中的一个成语“三心二意”是相通的，可以将其视为一种方言变体。

“三神”是古汉语中的习用词，可有很多意思。“三”往往用于实指或虚指数量，如“三元”、“三军”、“再三”，等等。

而“三”和其他数目字又常常连用构词，比如“二”或“两”就常常用来搭配构成习语，如“三心二意”、“三长两短”、“三天打鱼两天晒网”等等，这里也是类似的用法，是某地的方言而已。

i.e.

First of all, this is a dialectal phrase (it's very likely that it is a dialect of the Sichuan province), and is anything but a common standard Chinese phrase, but used in this novel it is proper, it mirrors the area the characters live in, it properly reflects the characters' natural characteristics.

Indeed, the meaning of “三神不挂二神” is "not concentrated, with mind not set into what one is doing", 神 indicates the mind, as for example in "心神不定” (uncertain in mind)，“神智恍惚" (with an absent mind, distracted), and so on.

Indeed “三神不挂二神” is related with a Chinese 成语 (saying), “三心二意” (lit. three hearts and two thoughts, i.e. half-hearted, shilly-shallying), you can view it as a dialectal variant.

“三神” is a common phrase in Classical Chinese, and can have many meanings. “三” (3) is often used to really or figurately mean a quantity, as in “三元” (3 yuan)、“三军” (lit. three armies, i.e. lower upper and middle army)、“再三” (lit. again 3, i.e. over and over again), and so on.

And “三” is often linked with other number characters to form a compound word, e.g. “二” or “两” (2) is often used to pair up [with “三”] and constitute an idiom, as in “三心二意” (lit. three hearts and two thoughts, i.e. half-hearted, shilly-shallying), “三长两短” (lit. three long and 2 short, i.e. unexpected misfortune), “三天打鱼两天晒网” (three days catch fish, two days dry the net, i.e. not persevere in doing something, not do something to the end), and so on, here it is also a similar usage, it's a dialect of some place and that's all.