Back before the current flag, Siam used a red flag with a white elephant:

Legend has it that the king, to his horror, encountered one of these flags upside-down, and to avoid that from happening again, decided to change to a flag that could not be turned upside-down. As a consequence, the following flag was adopted in 1916:

As you can see, the blue field was red back then. Allegedly it was changed to blue to show allegiance to the Entente powers during WWI, since they had blue-white-red flags. Alternatively, blue was associated with Friday, the weekday the king was born. Or alternative to that, blue just made the flag a lot prettier (which it indeed does).

Wikipedia article about the flag