I spent the weekend visiting AT&T store where I bought the phone a month ago, two different Apple authorized service centers, and finally the Apple store. As i explained to them, the phone will not connect for more than 30 seconds to CarPlay - in my car, in my sons car, in my neighbors car, regardless of what cables I use (including Apple brand cables). Yet everyone else's phones work just fine in all cars using all cables. I notice on some cable connectors, the tip is very slightly longer and will insert deeper into the phone than others. This does seem to help, but it's still not a stable connection. Move the phone and poof - CarPlay is gone. One of the techs said he finds customers with this issue often, so even if they replace the phone, it's a crap shoot whether you will get one that is good or not. Very reassuring !! In short - it's a "known issue".
The Apple techs did a diagnostic on the connector and internals - nothing was found. I would have sworn the connector itself was the issue, either loose or misaligned. To my dismay - nothing was found. SO the only thing they suggested was a total reset of the phone, removing everything and starting from scratch...NOT a restore from iCloud, because they believe there is a software glitch somewhere so it has to be a total reset. And then spend considerable effort trying to get all my apps back - from scratch. No guarantees this will work, but it's all they could suggest. Im not going to do that. If I move the phone and lose a connection - that is not indicative of a software glitch...it's hardware. Period.
I got one of those dongles that connects your phone to CarPlay wirelessly. That eliminates the connection issue. It works fine but doesn't charge at the same time.