Off the shelf bikes are competing on specs; in particular, they are competing on spec'd parts that buyers pay the most attention to: frameset, derailleurs, crank. Notice I didn't say groupset, because that term implies a full suite of components that are often not included with the off the shelf bike. The parts that are below buyer's radar are where they save money. When you build a bike yourself, you're probably not going to spec Ultegra level derailleurs alongside a house branded budget hubset, BB, seatpost. chainrings, seatpost clamp, spokes, etc. But off the shelf bikes will be spec'd exactly like that. The off the shelf bike will nickel and dime you, or in today's dollars $100 and $500 you, until it might end up close to the DIY bike.
It might *still* be a better deal, depending. But it's not as bad as it looks on paper.