The first variable is the size itself. When talking about folding
city bikes, they have to be as compact as possible so you can take
them as normal luggage when folded.
There's also the aspect of weight - smaller wheels are lighter but
also have lower rotational inertia. This means they are easier to
accelerate but once they gained speed, they don't hold it for quite
as long as large wheels.
In mountain bikes the wheel size is a very individual thing. Smaller
wheels offer better acceleration an better maneuverability (such bike
is generally shorter and of course requires less force to turn a
wheel). On the other hand, large wheels give better angle of attack
meaning it's easier to roll over any terrain obstacles. Also, on a
larger wheel you can have larger contact patch giving better grip.
There's also a question of stiffness, Small wheels, especially in
cheaper ranges are stiffer because of shorter spokes used.
In most disciplines of cycling the wheel diameter is 550-650mm (not
too precisely), so the differences are not enormous. Smaller wheels
are used in folding bikes and BMXes - in the latter because of easier
handling of a sherter, lower bike both on the ground and in the air.
I've partly mentioned the changes in bike geometry, but I'd like to
make it clear - wheel size can affect your position on a bike. In
particular when really large diameter wheels are used, handlebars
will be up pretty high and there's little you can do about it with
manipulating the frame geometry.
There's no single standard of wheel size for any bike types, which shows that manufacturers change their approach and priorities over time. It's also hard to determine the perfect wheel size for each person (talking about MTBs here), because it depends on people's personal preferences, experience and use of the bike.