Pokemon gain EV's for every Pokemon they defeat in battle. It doesn't matter whether that battle is wild battle or a trainer one. This is the reason why it is best to keep your in-game and competitive teams separate, as your in-game team is impossible to EV train properly.
The only time when defeating Pokemon does not give you EV's is when those battles give you no experience. This can happen if the Pokemon you are training is Level 100, or if it is something like the Pokemon World Tournament, where you don't get experience for winning.
Source for more info on EV's