In this particular case, anime is not different from any TV-series (if you want an example, take caprica, which was canceled mid-season due to low ratings). Let's start with some simple points:
- The production of anime episodes costs money.
- To get your work aired on TV, you need even more money.
Actually, you could check this question which approximately shows how much does it cost. It's a lot of money.
So, obviously, when you make an anime, you want your incomes to be larger than your expenses. How can you achieve that? Commercials. And, of course, the more popular is your show, the more people will see it. The more people will see it, the more people will see the commercials. So, basically, the more popular your show is, the more money you make from ads.
The second way is to sell different merchandise like t-shirts, figurines, and stuff. Once again, the more popular the anime is, the more people will want to buy this.
The above explains how things go if everything is fine. Sometimes everything is not fine. If your show is not popular enough, and the incomes do not cover the expenses, you bear losses. So, if you ended up loosing money after making the first season of an anime that was supposed to have 2 seasons, will you risk making the second one? I doubt that.
Now, as for the point on how the story is divided into seasons, it may also matter. For example, if a manga is very popular, then you might expect the anime based on it being popular as well, and plan X seasons in advance. On the other hand, if you are not sure, you may plan the first season only (with enough episodes for the story to reach some point where it can be stoped), and see how things go.
It also depends on the genre and the plot itself. For example, if each episode tells a small story which is not-so-strongly connected with the previous and the subsequent episodes, you may end a season at any time. But if episodes are closely connected story-wise, you may only stop when the plot comes to some kind of a logical conclusion (note, that doesn't mean "the plot ends", it just means that there is a point in the plot when you can end one season, and start another one without breaking the story and without losing viewer's interest, e.g. Code Geass).