>>30358455When you catch or KO a pokemon, it gives you 1-3 EVs in a specific stat, based on what the pokemon is. Some give multiple stats (Carbink, for instance, gives 1 each of both defenses). When you defeat a pokemon after it calls for help, it and any pokemon called in that battle will yield double the EVs (so that Carbink that called another Carbink will give you 2 EVs for each defense, as will the thing it called). Ideally, you want to also grab the Power items from the Battle Tree, as they give a bonus to the EVs you gain (which is a flat rate added to the EVs of pokemon you defeat, and is also doubled if you SOS chain). If I recall, they're 16 BP each.
Alternatively, if you're ultra lazy and don't mind the wait, 63 sessions in Poke Pelago's Isle Evelup will fully train the chosen stat for the pokemon you put in there (it's +4 EVs in the chosen stat per session). That's almost 32 hours without beans, though, and it only trains up one stat.
It takes 4 EVs to make a stat's value go up by 1 point, and your pokemon only can hold so many EVs. Usually you have enough to fully train 2 stats, and a little left over to partially train a third.
I think that about covers it.