The real reason why Don Knotts wasn't in the pilot episode of The Andy Griffith Show
Simply put, there wasn't a Barney, yet.
Pilot episodes rarely accurately represent the shows that follow. While it may be tempting to see the pilot as just "the first episode," the truth is that they're more of a "proof of concept." Pilots are used in selling the show to networks, not moving the plot along. So, lots of times, they bear very little resemblance to the finished product that audiences fall in love with.
This is true of The Andy Griffith Show.
While the pilot episode establishes Mayberry and many of its citizens, the story is very different from what fans would later identify with The Andy Griffith Show. For instance, the primary focus of the episode is Danny Thomas, as his show, The Danny Thomas Show was actually how the pilot aired. This early incarnation of The Andy Griffith Show was considered a "backdoor pilot," wherein an episode of an established show, with a built-in audience, is used to introduce the stars and characters of a soon-to-air program.
This pilot episode featured Andy Taylor as sheriff. Ron Howard also stars as Opie. Even Frances Bavier is along for the ride, here starring as Henrietta Perkins instead of Aunt Bee. But while there may have been some familiar faces already in Mayberry, there was one notable exception.
Deputy Barney Fife did not yet exist.
According to Griffith himself, Don Knotts was sitting at home watching TV when he saw his friend Andy Griffith on The Danny Thomas Show. Griffith and Knotts became fast friends on the set of No Time For Sergeants, a 1958 movie they both starred in. Knotts called his friend, asking to come aboard the brand-new show. Griffith told Knotts to call the producer. Then, as he was hired, Knotts "created that character of Barney Fife, as sure as he's settin' right there.," according to Griffith.
The creative partnership proved profitable and fulfilling. Audiences loved Barney and Andy, and their friendship was clear onscreen and off. Knotts' daughter, Karen, wrote of the relationship in her memoir Tied Up in Knotts:
"Andy was my dad’s biggest fan. He was a mentor to him his whole life, and they loved each other dearly."