It is a very tricky question to answer but I'll give it a go. It depends. That is I think it's possible to build a bike that is more capable in technical riding than one you can buy but it's not easy. I'll present some examples.
You can build a bike that is more tuned to your riding than buying one. For instance I built a bike for a friend, started with an older carbon Santa Cruz Nomad, added a CYC stealth and a very small backpack battery. The whole set is probably lighter than most production bikes and has more power and a throttle (I'll get into what that is important later) and it is very well suited to her use in ways that most production bikes would not. They would be heavier because of much larger batteries that she would never use more than 10% of on any given ride. The added power with throttle allows traversing terrain that would otherwise be difficult in pedal assist only. But there are tradeoffs, obviously limited range, motor is noisy, torque sensor control is OK but not amazing, battery frame mounting would be possible but would require some work.
My bike on the other hand twists some of the dials to min-max things a bit more. My "trail" bike is a 2010 Santa Cruz V10 with an Lightning Rods Small Block, VESC, and prismatic lipo battery. It still weighs about as much as a heavier production eMTB (58lbs last time I checked) but exchanges many features they have for others so it can outperform them on based on my riding style and terrain. I'm not into jumps (although I don't see why it wouldn't jump nicely), I don't generally do all day rides (2-3 hours or so normally), I don't care about pedaling (I have other bikes for that and would rather be tired from technical terrain and distance, not having and asthma attack 2 min in) and I ride in New England where all trails are rocks and roots and everything is weird awkward little hills. So I built the bike to suit, battery is 576wh and could have been smaller, it basically can't be pedaled, only has throttle and has enough torque and power control to climb anything I point it at. Using a throttle through very technical terrain is probably one of the biggest advnategs a DIY bike has. When you can focus on balance and lines while your body is stationary and you don't have to worry about pedal strikes the terrain to skill ratio really goes up. Given the best production bike no way I could climb things I can climb on this bike. The bike may have a 6kW motor on it but I never use anywhere near it's power on rides, it's the control and response that power provides. It has a single speed drive and I have as much torque as I need 100% of the time, no gear changes, no power bands to worry about, no short burst of power that backs off due to a limiter. Does the bike still have improvements that I would like to make, for sure, even a few issues to resolve. Is the battery an insane tetris block, oh yeah. Does the bike have more custom parts than I can count, many of which to solve weird problems that only exist to work around the DIY nature of it, for sure.
I guess my point if I have one is a DIY bike allows you to build a bike more suited to your needs so it can be better, with enough work, but it does somewhat rely on the advantage of being able to be tuned for it's use. That is making comprimises in some areas to benefit others. Which also means if it's use is exactly what the production bike was designed for it will be very hard to beat it.
If you are focused on torque sensing, I've never tried a production ebike so I don't know. From what I've heard and tried, the Tosevens is not amazing torque sensor wise, the CYC after some tuning is OK, my first bike was a TSDZ2 with OSF and that was quite good but the motor power curve is weird so requires a lot of shifting. For my riding I would rather have a throttle even if only using it in particularly difficult sections than a perfect pedal assist, so OK pedal assist + throttle I would prefer of perfect assist no throttle. But that's because I have a lot of areas that are very rocky and technical. If you're doing more fire road climbs and descents then that's different. In fact I think the throttle on my TSDZ2 even with it's picky motor still dramatically improves it's technical climbing capability, it just does it very slowly but a technical climb done very slow is still easier than a technical climb done slightly faster but you have to pedal the whole time.
Now when it comes to descending I don't really know that either has an advantage. I mean assuming you position the weight well the weight balance is pretty similar. Suspension and geometry will be the same. The weight though is a complex subject and there is some personal prefrence. While this may sound crazy as I just said by bike is 58lbs, I try to make it as light as makes sense. So yeah that is heavy but it's also a DH bike with 200/254mm of travel so the bike wasn't light to start and I spent that weight well. I find and I've seen many professional riders comment on the fact that the weight does improve handling over rough terrain. This is due to the ratio of sprung to unsprung mass. Meanwhile if you are very active on the bike and ride in ways and places where that works, so lots of hops and bike reposisions the weight can really be a drag.
I feel like cost wise it's just so variable it could go either way. Maintaince wise I think a DIY bike will require more at least at first but making improvements is part of the fun for me. Again you really have to consider if you just want a bike to ride or a project. A quick an dirty build probably will be worse in at least some ways than a production bike while a well built bike I think can be better but that takes time.