A Marine Corps band first played "Hail to the Chief" for Andrew Jackson as he walked off on his way to Ohio. It earned three cheers from his adoring crowd. After President John Tyler adopted it for his 1841-1845 term in office, the tradition stuck and American Presidents have been associated with the song ever since.
But before that, they tried to choose a personal theme song. Thanks, John Tyler.
George Washington almost had "Hail, Columbia" as his theme, with lyrics like "Let Washington's great name ring through the world to loud applause." And Jefferson tried to get "Jefferson and Liberty" as his theme song, with lyrics like "But join with heart and soul and voice, for Jefferson and Liberty!"
Some Presidents had special songs written for their campaigns that would have worked as an entrance theme, like Warren Harding's "Harding, You're the Man For Us," Richard Nixon's "Nixon Now," Barack Obama's "Yes We Can," and the ill-advised "Get On the Raft With Taft."
In the January-February 2017 issue of Smithsonian Magazine, Abigail Tucker detailed the history of the song and how it came to be played for the President of the United States. In the early days of our nation, the general population wasn't too fond of the British. So when a theatrical version of the 1810 poem "Lady of the Lake" premiered in Philadelphia, it really caught on.
The show was an epic historical story about the life of an anti-British elite who is destined for greatness but whose life is tragically cut short by a power hungry villain. The stage show was a musical production that American audience immediately fell in love with and soon the whole country was raving about the show and its songs. So it was basically the "Hamilton" of the 1800s.
After the War of 1812, anti-British sentiment was still riding high and even though "Lady of the Lake" was about an anti-British Scotsman it hardly mattered to Americans. He was an awesome character and that was enough. The lyrics were changed a number of times, however. Poetic olive trees eventually replaced Scottish pines and the hero of the song stopped murdering British people.
Eventually, people completely forgot the official lyrics of the song.
Today the Defense Department mandates that "Hail to the Chief" only be played by the Marine Corps band in B-flat major and only for a sitting President in a "stately context" and at Presidential funerals.