Where did that energy come from? The answer is that it came from the battery that was charging the capacitor. I won’t go into details, but the point is that when we defined the system to consist of just the particle, we narrowed our focus to just a part of a bigger system that includes the capacitor and the battery.