There was higher O2 in certain periods which allowed bigger insects ( insects breath by gas diffusion which limits their size). Not all dinosaurs were big, it is just easier to find and identify large fossil remains and museums + hollywood don't focus on little creatures
For plant eaters it is likely that the poor quality vegetation avaialble (woody ferns) means you need a long time to digest them, which means you need to hold a lot of 'stock' in your stomach whih means a large stomach and so a large body. The same reason we have elephants. If you have large prey, you need to be a large predator to take them on.
There are also thermal advantages to being large if you are cold blooded, it's easier to keep a large body warm in cold climates than a small one.
Interestingly population models suggest that the mass of large predator dinosaurs/area is about the same as the mass of African big cats/area, when you take out the relative efficency of mammal/reptile bodies.