Trainers can only carry up to 6 pokemon, the other ones are kept in boxes in the PC
They keep those pokemon/pokeballs in the order they choose(and in the games the first one always goes first in battles), so they probably would know where which pokemon is.
In the anime(iirc) there were times when people tried to use someone else’s pokemon, and ended up not knowing what was inside the pokeball.
In the manga, they could see a mini version of the pokemon inside the pokeball
So how they know probably depends on the pokemon universe(but it’s likely that after a while they can tell just by touching the pokeball)
(And there are many kinds of pokeball too, so they could know that the pikachu is in the pokeball, and the raichu is in the premier ball, etc)
Edit: Ninja’d by palmtop