There are advantages and disadvantages to each wheel size popular today (26", 27.5" and 29"). The larger the wheel, the easier it rolls over obstacles. However, with a larger size, the weight and thus the rotating mass increases. Thus the agility of the bike decreases. With identical tire and rim dimensions, as well as same air pressure, a larger wheel increases the contact area of the tire on the ground. Larger contact areas then lead to improved traction.
Why are there different wheel sizes for mountain bikes?
If an obstacle remains the same size but wheel size increases, then the rollover angle becomes smaller. Therefore, large wheels roll over uneven ground with less resistance - so less force is needed to overcome obstacles.
Wheel size cannot be adjusted arbitrarily on most bikes, as the geometries of mountain bikes are developed with specific wheel sizes in mind (e.g. the chainstays of a 26" bike are usually shorter than those of a 29" bike).