Spaniels are docked because their primary job is to flush birds from cover. That means entering thick brambles etc, often at high speed and with a wagging tail, so you can end up with some horrible injuries where the cover rips the tail open.
The Irish Water Spaniel (and American Water Spaniel) are exceptions to the Spaniels docking rule, as they are classed as retrievers, not flushing dogs, their natural landscape is also bogs, so not much to shred their tail were they to end up in cover.
Labs are used primarily for retrieving, so they often won't be entering the same sort of cover. If the do, they tend to go over not through it and rarely hit it with the same ferocity of a spaniel. Same with any breed of retriever.
These two I'm not 100% sure about, but I think Hunt, Point, Retrieve dogs (Vizlas, Weimeraners, GSP/GWP) are docked because again they are hitting cover to flush game, whereas Setters were used to trap game, so agin would not be hitting cover, hence the lack of dock.
Rotties were originally used to herd cattle in Germany. My brother breeds them, so I will ask him why they were originally docked, but I think it was something to do with cattle being able to grab hold of their tails?