Rifled barrels were mostly used in WW1 - WW2, mostly because of the types of shells that tanks would fire. They would use just normal bullets, which fly straighter when spinning. The spin is created by the grooves in the barrel of the gun, which was sort of just a coil pattern going until the end of the barrel. This also made the shells that they were firing be able to go off, as the firing pins used were released by spinning, so if someone was just carrying it it wouldn't go off. That is one of the reasons why when people find explosives they shouldn't mess with them, as if you turn it the right way it may detonate. Even with modern grenades, spinning them can set them off.
Smoothbore guns were used from pre-WW1 and past WW2. The main reason was that anything a cannon from the 1800s fired didn't need to spin, as they were usually just a heavy ball. These do not have grooves on the inside of the barrel and thus makes less spin. On modern tanks, these are used because of the adaptation of APFSDS, which is just a steel dart with fins on the back for stabilization. These also move very quickly and can go through a lot before losing momentum, which is necessary against the composite armor on modern MBTs.