After the end of the Space Shuttle era, NASA planned to convert both launchpads to support launches for the Constellation program.
The last few Space Shuttle missions from 2009 until 2011 all launched from 39A. So NASA began rebuilding 39B for the test flight of the Ares I-X in 2009 as part of the Constellation program.
But as it happened, the Constellation program got cancelled, and now both launchpads were unused.
Since NASA already made upgrades to the 39B pad, they wanted to keep it for the Space Launch System and continued to rebuild it. Thus 39A wasn't needed anymore, so they decided to lease it to commercial users instead.