That isn't always true. Lots of local bike shops are frankly a bit rubbish and don't always do a great job. It seems to be an internet myth that a local bike shop is always good but when you look at reviews many are quite poor.
Halfords often get a bad rap and rightly so I'm sure but they take about 25% of all money spent in the UK on cycling and supply an estimated 40% of all bikes sold in the UK selling more bikes than the whole independent bike shop sector by some margin. Remember the bulk of bike sales are at low prices and there is
ebay, amazon, argos, evans, decathlon etc. Local bike shops often sell far more of the higher end models too which are likely to be better setup at the factory. I've read a few reviews of my local bike shops in the past and there has been quite a few issues in a similar way to Halfords. My own experience of a local bike shop is my bike wasn't setup great and when I returned it with a fault there was a lot of excuses and it almost felt like I was taking food out of their mouth. They reluctantly sorted out the problem. That was many years ago but I don't think all independent bike shops offer great service.
Looking at my local bike shops; Tri UK scores 3.7 out of 5 based on 198 reviews and Halfords scores 4.4 out of 5 based on about 400 reviews. Tri UK bikes are obviously a lot more expensive and more premium on average using higher end components. Halfords do a lot of bikes based on very low end parts that would likely to be more problematic.
I should add the only bike I have ever bought from Halfords was a Carrera Subway 8 which had both hub gears and hub brakes a fairly complicated bike. When I went to collect it, it had a free upgrade to a Shimano bottom bracket fitted as the stock bottom bracket was faulty (chin lang or something like that unit) and the bike operated perfectly and was fantastic. After 6 weeks or so I returned it for its free service and that was the last time it went into Halfords but the customer service was great, no issues.
Anyway I've discussed this many times in forums over the years and many people have also said they have had terrible customer service from their local independent bike shops so I don't know where this myth has come from. Like anything there are good and bad shops out there and you need to check reviews of your local bike shop before buying there just like any shop really for a major purchase which most bikes are.