Wheel size tends to go with the type of bike. Road bikes tend to standardise on 622mm rims (aka "700c" - don't ask) Mountain bikes tend to have 584mm rims (aka "650B" - no, really, don't ask). I think these are roughly 29" and 26" but don't quote me. Folding bikes and shopper bikes have smaller wheels, for example the Brompton has 349mm rims (16")
Why the different sizes? The wheel size tends to go with the design of the bike and its frame.
The small wheels on a folder like a Brompton are necessitated by the bikes design. They don't cope well with particularly rough surfaces but they need to be small for the bike to fold up small.
I don't know anything about Mountain Bikes but I do know they can come in both 29 and 26 inch and people like to argue/discuss about them.
Road bikes are pretty much universally 700c (622mm) although with the advent of disk brakes there are some gravel bikes that can run both 700c and 650b wheels. With rim brakes you were stuck with one wheel size. Also, smaller riders may prefer smaller wheels as a small frame with big wheels can be unweildy. But this can be a problem for small pro riders as they need access to standard spares during races. Emma Pooley (a small but nonetheless very successful pro rider) talked about this.
That's wheel size, which is one aspect of the size of a tyre
Then there's tyre size, which is how fat the it is. Typically the fatter the tyre, the rougher surfaces it can deal with, and the lower the pressure it can take, and fatter tyres tend to be more comfortable. In an ideal world skinny high pressure tyres are faster - and that's what they use on the almost ideal surface of the velodrome. But on the un-ideal surfaces of real roads this isn't true. The question of tyre size, rolling resistance and pressure gets debated endlessly. Frame design comes into it too. Some frames limit the maximum tyre size because they don't have room ("clearance") for fatter tyres.
Tyres with grippy patterns (eg Mountain bike "knobblies") are for when the surface is softer than the tyre itself (eg grass or mud). Where the surface is harder (eg tarmac) slicks are generally used. There are also half-way tyres for use on tarmac that have grip patterns - about which there are often arguments (they provide grip/no they don't they are purely cosmetic).
Then there's the question of tubed versus tubeless, and you have fuel for endless arguments.