Shakespeare is trying to tell us that surface appearances deceive and that there is deeper reality hidden beneath the way things or people appear.
For example, disguised as "Balthazar" in the courtroom, Portia appears to be a male lawyer, but is, of course, a woman. In the same way, her "Clerk," who also seems to be male is, in reality, her female servant Nerissa. Their gender bending surface appearances mask the deeper reality (unacknowledged in that time period) that women were just as capable of being lawyers and arguing persuasively as men. In fact, Portia argues eloquently for mercy towards Antonio and wins his freedom from having a pound of flesh cut from his body. But without projecting the illusion of being male, she could not have saved Antonio.
In having a woman competently defend a male, Shakespeare suggests to his audience that the appearance in his society of women as weaker and less capable is not reality. He thus invites to look beneath the surface of people to see who they really are.
Likewise, in choosing the correct casket for Portia's hand, the winning suitor must realize that "All that glisters is not gold." The gold casket may look most attractive on the outside, but it will not win Portia's hand. One, the other hand, the lead casket does not appear attractive on the outside but represents inner beauty—Portia's picture is inside. It states "Who chooseth me must give and hazard all he hath," showing that sacrifice is the way to win the heart of a beloved, not money or outward appearance.
Shakespeare is trying to say that, despite surface appearances, what matters most in the world are traits such as mercy, a willingness to sacrifice for others, love, loyalty, and friendship. Perhaps Bassanio didn't need to borrow money to project the illusion of wealth: perhaps what really mattered was his heart.
You might look at Shylock too. Beneath his anti-Semitic portrayal, even he has a heart: he grieves, for example, when his daughter Jessica elopes with a Christian.