When King Louis XIV was 5, a revolt broke out in Paris. The rebels were led by the disenfranchised aristocracy who believed their power was being threatened. Although this revolt and another after it were put down, it became clear that the aristocracy had to be controlled.
Louis had this in mind when he became king. Versailles before the reign of Louis was mostly used as a royal hunting lodge; but Louis had other plans for it. In 1661, he began expanding it into his personal palace. Upon its completion in 1682, Louis moved in, and changed the capital from Paris to Versailles to escape the turmoil Paris was subject to. He invited all of the aristocracy to live with him on the grounds, not because he liked them, but because he could control them.
The magnificence of the palace is incredible; acre upon acre of gardens, parks, fountains, and walkways stretch across the palace grounds. So it’s no surprise that when invited to live there, most of the aristocracy accepted. In this way, Louis was able to keep himself safe and make sure the powerful aristocrats were unable to overthrow him.
Of course, a more obvious reason why the capital was moved is simply because Versailles is so beautiful. Louis could stroll along the palace paths and enjoy the beauty (though he usually didn’t have enough time for anything but work).