Money comes from the team owner, (or the corporation that runs it for him) Revenues, (income) are generated from ticket sales, sponsorships, percentage of food and souvenier sales, etc.
There are teams in a large market. That is, in an area where there will be a lot of people supporting the team and buying lots of tickets, for every game. Smaller market (for example, in a smaller city, or a city not near many other cities) teams will not have the same size fan base. Fewer tickets, less money coming in.
Winning teams also generate more ticket sales and can ask for more money from the networks who want to broascast their games. Again, more money.
Some teams are perennial favorites, who may have both of the above mentioned advantages, or are just well known enough that their games and their branded products are in high demand.
Thats one of the reasons salary caps were instituted in some sports. The league owners realize that they need to make the game more competetive to keep fans interested. Salary caps are a way to prevent a team owner from pouring an unlimited amount of money into salaries. Wthout the caps, the team with the deepest pockets could buy the best players and no one else could win.