In the case of Stephen King/Richard Bachman, those books were originally just credited to the Bachman name and reissued once it became commonly known that Bachman was King. King wanted to avoid oversaturating the market by releasing more than one book a year. He also wondered if a book he wrote could succeed under its own merits rather than just because it was published under the name "Stephen King." The
Wikipedia page on Richard Bachman gives a good overview of the situation, as well as how it was discovered that King was Bachman.
Sometimes a pseudonym or an additional credited writer can just be the author having a bit of fun. Nicholas Meyer is credited as an editor on all four of his Sherlock Holmes novels*, with "Dr. John H. Watson, M.D." as the credited author, and the 2008 James Bond novel
Devil May Care is credited to "Sebastian Faulks, writing as Ian Fleming."