Both date to the earlist days of electric trains, but because of advantages in electric wiring (simpler) 3 rail was chosen as standard by the major manufactures both in the US and Europe. (Even early HO was 3 rail as Marklin still is)
In the early days most toy trains were what is often called “tinplate” today. Fidelity to scale was often coincidental.
Some modelers wanted scale so they scratch built, converted timplate and purchased the few scale items that were available. They built their railroads with T rail, converted to smaller (but still ovesize) flanged wheels, and many also used outside third rail similar to some prototype electric railroads The geat model railroader Frank Ellison had 3rd rail shoes on his scale steam engines.
Eventually many O scalers went to 2 rail, but 3 rail still remains more popular.
O is now divided onto 3 broad catigories: O gauge - mostly the traditional timplate although some approaches scale. O scale 3 rail, O scale 2 rail
3 rail has traditionally had the advantage in simpiler wiring, remote control and automatic action, singnaling, and sound. Advances in electronics are now bringing these features to 2 rail.
3 rail is is usually more robust and may have some out of scale details in addition to the oversize wheel flanges and sitting higher above the rails. It also will operate on sharper curves.
Some 3 railers are now doing a compromise between 3 rail and 2 rail using wider curves, body mounted couplers and 2 rail trucks.
I have heard that one manufacture is planning to make locomotives with smaller flanged wheels that they will be easily convertible between 3 and 2 rail.
I play around with 2 rail, but many of my cars are converted 3 rail[:)] My locos are a 2- rail brass steaplecab electric, a 2-rail GE 44 tonner, a 2-rail Atlas SW and a 2-rail Weaver VO1000.
The recent introduction of 2 rail track by Atlas is helping to spur the 2