During the war of 1812 between the United States and Great Britain, the president’s house was taken over and burnt by the British on 1814. At that time, James Madison was the president and was residing there; however he had left to a safer place. The house was completely damaged, and Madison brought James Hoban (the architect who designed the house) to restore it. It was during the reconstruction that the house was painted white. Something worth noting is that the house was first made white with lime-based whitewash (Whitehousehistory.org).
Although the term “White House” was used for some time, President Theodore Roosevelt was the one who gave the White House its official name. But there really is no specific reason on why the house was painted white. However, I think it was because the house just looked better painted white to make it look pristine and neat and they decided to keep it that way.