It seems to often be a power problem between the iPad and the laptop. When you connect with he charging cable, the laptop is actually charging the iPad in addition to the data exchange between the two.
1. Reduce the screen brightness on the iPad. This reduces the power draw from the laptop.
2. If that doesn't help, you can reset the power manager on the laptop. Follow the link in the footer.
Check first to see if your MacBook has a
T2 chip (only around since 2018)