"I am going on a long drive tomorrow. God forbid it should rain really hard and I crash the car!"
Obviously, heavy rain and a car crash are two things you don't want to happen so you want "god/God" to "forbid" (prevent) them from happening.
In the dialogue you quoted, it is used sarcastically. Of course, you would actually want the star witness in a trial to appear clever (intelligent) but Sherlock is rather upset that John is telling him that he shouldn't seem overly clever (if you are watching the series, you will know that Sherlock can be brilliant but also very sarcastic and he doesn't deal well with authority! He can be, as John later says, a "smartarse"!) Consequently, he sarcastically says that it would be ridiculous to want the star witness to seem intelligent.
As you can see from the dialogue, there is an implied difference between "clever" and "intelligent".