Try these checks in order:
- Set Windows to a higher performance power mode.
- Go to Start > Settings > System > Power & battery.
- For Power mode, select Better performance or Best performance.
- Test the controller again while charging.
- Update Surface drivers and firmware if this is a Surface device.
- Open the Surface app.
- Expand Help & support.
- Select Check for updates to open Windows Update and install available updates.
- If Microsoft Teams is open while gaming, check whether Xbox Game Bar has remembered it as a game.
- Make Teams the active window.
- Press Windows key + G to open Xbox Game Bar.
- Go to Settings > General and clear Remember this is a game.
- Go to Settings > Capturing and clear Record in the background while I'm playing a game.
- If needed, turn off Xbox Game Bar temporarily to test whether it is causing the lag.
- Go to Start > Settings > Gaming > Xbox Game Bar.
- Turn off Xbox Game Bar.
- Test the game controller again while plugged in.
- Let the device cool down and keep it plugged in.
- If the device feels hot, move it to a cooler place and wait five minutes.
- Close memory-intensive apps such as streaming video or other games before testing again.
If the problem happens only when charging, the most directly supported fix is changing the Power mode and checking for updates. If Xbox Game Bar is interfering in the background, disabling it is the next useful test.
References: