This question already has an answer here:
- When does your pokemon get CP at a gym? 3 answers
If you train at a gym (one on the same team) you can gain experience and prestige.
But does training help the CP of the Pokemon who was battling? It would seem to make sense, but I haven't seen evidence of it happening.