I couldn't find them quickly, but Bob and Suzanne did interviews about this scene.
The idea was actually from Bob's wife: Ginny. She made a joke about it at dinner with Bob and Suzanne during the second season of Newhart. At that time, they thought the producers would never do it. But, out of the blue, they called Suzanne during the last season - and she immediately knew why before they even explained.
They kept it a secret from the rest of the cast, and floated a bogus story about how Bob would have a conversation with God (played by George Burns). The rest of the cast was finally briefed just before the scene was filmed.