It's actually a less optimistic quote than its modern-day usage tends to be. We tend to imply the sense "even poor-looking things can have worth", hence that the LEAD casket is more valuable than the GOLD. Yet what Shakespeare says is the glass-half-empty alternative: "sometimes worthless things glitter like gold does".
It strikes me as quite a pessimistic quote in a pessimistic play. Is there anyone we like in "The Merchant of Venice"? Portia brutally dismisses Morocco on account of his "complexion" at the end of a double-scene which begins with him asking for racial equality ("Mislike me not for my complexion"). The Christians seem a pretty vicious bunch, all (Bassanio included) wealth-obsessed: and Shylock, despite modern critics reclamation of him, is still a volatile and extremely dislikable figure in the final trial.
I've always thought of the quote above in a generic sense about the play itself: it has all the ingredients of a comedy (look at the collocations Shakespeare draws in Act 5, Scene 1) but rather than a glittering romance about witty young people getting married, it's an unpleasant, capitalistic play about people obsessed with money. "The Merchant of Venice" glitters like a golden comedy, but - after that first impression - turns out to be something rather more leaden.
(Not wishing to nit pick, but the exact line is, 'All that glisters is not gold...')
I suppose this phrase warns us that we should be careful of accepting easy first impressions and shallow judgements about situations and people. MoV is obviously about the clash of race and religion, so there are many examples that would fit.
Should we see Shylock as simply 'An Evil Jew' who lends money and plots against the 'golden' Antonio, the Christian. If we look more closely at the situation, we can see Antonio is not so perfect or good, not so golden.
Or the loan of 3000 ducats with the unusual contract... more careful consideration by Antonio would have revealed its less than golden appearance.
And Antonio is not worried about the contract because he says he's got lots of ships coming from all over the world, so he's a rich man who will repay easily... but they all sink, so his golden business plans are not what they appear.