I have the same or similar issue. What was so frustrating is that the problem seemed to be very intermittent.
Technical Details:
2018 Honda Accord - iPhone 15 Pro Max, SW 17.1.1 ( plus some earlier versions)
Problem:
1) Sometimes it connects to Carplay and it will work.
2) Sometimes it will connect and then disconnect, connect and disconnect.. (to include the charging of the phone)
3) Sometimes it will connect and the carplay will not connect, but it will charge the phone.
Troubeshooting:
I tried several USB-C cables to include a standard Apple USB-C with a couple of different USB-A to USB-C adapters. The adpaters were the same brand, but different adapters. The cables and adapters tested good in other applications (e.g. connecting to computer) and charging from power outlet. These same adapters and USB-C cables worked with carplay sometimes.
Tentative Resolution:
I noticed what seemed to be a correlation between the charge percentage on the phone and when the issue happens. I am not sure if there is an exact % charge level, but it appears that it happens when the charge is below 70% on the phone, but not when it is above that percentage. I haven't taken the time to try to pin it down to a specific %, but generally it seemed more likely to happen the lower the power level and I haven't yet seen it when the phone is closer to fully charged.