I had a similar problem, and solved it with a Shortcut which disables wifi whenever CarPlay is connected, and another to re-enable it when disconnected. Real easy since Shortcuts has built-in triggers for CarPlay.
Click on the Automation tab at the bottom, and at least for me, the "CarPlay" section (with an example "When CarPlay connects") is at the bottom of the second grouping of suggested automations.