Apparently, the title track was written as a potential theme for the James Bond movie You Only Live Twice.
From Rolling Stone (all emphasis mine):
The record's bossa nova-flavored title track began life as an instrumental called "Run James Run." The James in question is 007 himself. Perhaps inspired by the 15-second James Bond-esque theme that opens the American version of the Beatles' 1965 Help! soundtrack, Wilson apparently decided to take a stab at a full track. "It was supposed to be a James Bond-theme type of song," Wilson revealed in 1996. "We were gonna try to get it to the James Bond people. But we thought it would never happen, so we put it on the album." The cinematic orchestration hints that Brian Wilson could have had a strong future in film scoring.
But according to the Huffington Post:
The title track was originally meant for the James Bond movie “You Only Live Twice.” When the film studio declined, the band put it on “Pet Sounds.”
Wilson initially called the song that is now known as “Pet Sounds” something more fitting for its original intent — “Run James Run.” Although the exact agreement Wilson had with the production team behind the Bond movie “You Only Live Twice” remains murky — both credited producers are dead — Wilson confirmed he made the track for the film.
“They turned it down,” Wilson said, contradicting accounts that he actually never submitted the track after losing his nerve.
Further explaining why the track ended up on the album after missing out on Bond, [band member Al] Jardine said, “Usually, when you’d do an album like that in the old days, you’d have nine or 10 good tracks that you’re happy with, but you’re required to have at least 11 or 12. So we’d always make an instrumental track or two to fill out the album.” With a laugh, Jardine said, “That was available ... so that’s really what happened.”