There are many reasons why Louis built the palace of Versailles.
The main reason Louis xiv ordered the construction of Versailles was because it would give him all the power in France (absolutism). He would get this by making it his official residence in 1682 and by the moving government there.
By moving his government to Versailles it would mean all the nobility will be at his palace. He never achieved this as the cost of the construction was too much, however most of the nobility did move into Versailles and in Versailles Louis was able to control the nobility as they’d always wanted to be in the king’s favour. The construction of Versailles allowed this.
Another reason why Louis xiv ordered Versailles to be built is because showed his power in Europe. It showed his power to all the other leaders in Europe because it was a symbol of his own achievements on how he could have a ugly swamp transformed in to a beautiful palace. This showed the other rulers of his greatness and of how he had absolute power in France. Rooms like the hall of mirrors (completed in 1684) demonstrated the glory of Louis reign to the rest of Europe and even though the project it became a burden on France it showed the power Louis xiv had.
As you can see Versailles was built so Louis xiv could absolute power in France and was a symbol to the rest of Europe of Louis power over his people and showed how great his reign was to the rest of Europe.