There's no definite answer to this, however there are some theories.
Given that predators and prey exert control on each others' numbers, I doubt the amount of available food was responsible. Usually if there is more prey/food around, it just means that predators increase in numbers because more of their young survive. And how could T-rex grow giant 'because it could eat anything', if it would require it's large size in the first place in order to do so?
The real question to ask is what limits growth in animals. After all, the bigger a predator the easier it can kill, and the bigger a prey the harder it is to be killed. The natural 'arms race' of predator/prey relationships might be expected to manifest itself in continually increasing body sizes, with each trying to 'out-grow' the other to enhance its own survival chances. But in reality that doesn't happen.
For herbivores, the longer the gut the more efficient the digestion, so being as big as possible is also good for maximising the gut size and therefore the amount of energy they can get from their food, which is relatively low-energy in comparison to meat. This is probably why many herbivorous dinosaurs - most notably the sauropods - were enormous. And yet herbivores don't grow to such sizes today, despite this potential advantage.
The correct way to think about dinosaurs and size is to imagine that their 'size ceiling' was set higher than ours is today, and then to consider why this might have been - what limits were different for them than they are for us?
Giant Insects
Some groups of animals such as the insects are today limited by their armoured but brittle exoskeleton. If an insect grew to the size of a human, it would collapse under its own body weight. They don't have a calcified skeleton like we do, and the exoskeleton casing their legs would be too weak to support a huge body.
But another key factor in insect size is breathing. Insects breath using completely different apparatus to us; they have a series of valved holes along the sides of their bodies called 'spiracles', and when there are open air enters through them into a network of tunnels called 'tracheal tubes' than run throughout the body. Oxygen from the air diffuses directly into the cells from these tubes. If you know anything about diffusion, you will know that in order for it to work there needs to be a higher oxygen concentration in the air than inside the cells, and that the higher the concentration of the air, the more efficient the diffusion process is.
And it is this efficiency of diffusion that limits the size of insects. In a big insect, surface area to volume ratio decreases, making diffusion less efficient as is. And more importantly, oxygen levels today are considerably lower than they were when the giant insects were around. About 300 millions years ago, there was a phase known as the 'Carboniferous-Permian oxygen high', when oxygen levels in the atmosphere reached over 35%, compared to only 21% today. Back when oxygen levels were high, insects could diffuse it into their cells well enough to support the metabolism of a huge body, and in the fossil record from this time we see things like dragonflies the size of seagulls and 3 foot long scorpions. However in today's oxygen levels, that would be impossible, so giant insects like those of the past could never survive.
Another problem that limits size in temperature. It's okay for us as endotherms as we can generate our own heat, but (debatably) most dinosaurs were probably exothermic, or perhaps partial-endotherms at best. Global average temperatures were much higher when the dinosaurs were around than they are today. Large bodies take longer to heat up, again because of the low surface area to volume ratio. But back then, even very large dinosaur bodies would have been able to heat up from the sun, just like lizards today do. However if a dinosaur was alive in today's temperatures, in most places in the world it would be too cold for its body to warm up properly. Aside from the extreme of freezing, if body temperature is too low then bodies just don't function properly. Digestion slows down dramatically, blood flow and pressure change, enzyme function decreases... in short, it is too cold today in most parts of the world for dinosaurs to survive, but they could grow into giants in the past because it was hotter.