It is not entirely clear why the B flat became the standard trumpet, but it was probably because overall it had the most consistent and serviceable tone throughout the instrument. Another reason is possibly the popularity of the B flat cornet in France and elsewhere in the 19th century, which replaced the larger and less agile F and G trumpets. Size, flexibility, tuning-consistency as well as tone quality all played their part.
Before the invention or widespread use of valves, the key of a piece or movement would determine the pitch of the trumpet. But nowadays the fully chromatic trumpet makes changing trumpets unnecessary unless particularly requested.
Tony Cross talks about different trumpets, some of which have separate articles on them.