As Poe put nothing unintentional into his work, famously stating that every word had its purpose, we should assume that Montresor's statement that he belongs to the society of Freemasons has a meaning in the text. This is probably twofold:
Firstly, it foreshadows Fortunato's cruel death by live burial. The builder's trowel is a famous Masonic symbol. The fact that Montresor chooses to bring up the Freemasons and by doing so reveals the instruments of Fortunato's murder may show his eagerness to do the deed. Disguising it as an innocent Masonic symbol is his excuse to reveal the murder 'weapon', so to speak. Many killers are proud of their handiwork, with most believing they have committed the perfect crime. Montresor was probably no exception, as we see he cannot keep his crime to himself by the very telling of this story. The presence of the trowel thus serves to foreshadow the story's end and reveal Montresor's nature as a calculated killer.
Secondly, the dialogue between Fortunato and Montresor when discussing the secret and exclusive society of the Freemasons could also serve to demonstrate the men's relationship. Montresor never explicitly details the many injuries Fortunato has inflicted on his ego, but perhaps the slight of suggesting Montresor couldn't be a member of the Freemasons is such an example:
“You? Impossible! A mason?”
Even after Montresor insists and shows the trowel as proof, Fortunato is still disbelieving, saying,
“You jest... But let us proceed to the Amontillado.” (eNotes etext p.7)
We could take this as proof that Fortunato holds Montresor in no high regard, which surely frustrates the latter to the point of detesting the former. With a bruised enough ego from a thousand injuries (and perhaps a damaged psyche), Montresor has enough motive to plan Fortunato's death. Therefore, Poe might have inserted this bit of dialogue as an example of Fortunato's insulting demeanor. Montresor is exacting his revenge, but in order for that to be plausible we have to see what drives him to that extreme.
We may not know for certain to what end Poe included this mention of the Freemasons in "The Cask of Amontillado" but by analysis it seems to reveal a bit more of the nature of both characters of the story--one as a methodical killer, the other as his worthy victim.
Montresor says that he is a Mason to catch Fortunado off guard, and gain his trust.
Fortunado is a Mason, or a member of the secret elite society. Members of the secret society can trust each other, even if they do not know each other.
“You are not of the masons.”
“Yes, yes,” I said; “yes, yes.”
“You? Impossible! A mason?”
“A mason,” I replied.
“A sign,” he said, “a sign.”
“It is this,” I answered, producing from beneath the folds of my roquelaire a trowel.
“You jest,” he exclaimed, recoiling a few paces. “But let us proceed to the Amontillado.” (enotes etext p. 7)
Montresor is not really a Mason, but by saying that he is one he hopes to get Fortunado to lower his guard and trust him. It is part of Montresor’s plan to trick Fortunado into going into the crypt so he can bury him and get his sweet revenge. Forunado thinks that he is joking when he waves around the trowel, as if Mason meant literally someone who works with bricks.
In an ironic double meaning, Montesor does become a literal mason when he bricks up Fortunado, burying him alive in the crypt.
It should be noted that Montresor acts in a somewhat zany manner after he and Fortunato are down in the catacombs. Poe always has a purpose, even a dual purpose, for everything in his story. Montresor wants to keep Fortunato intoxicated, but in order to do so he has to drink with his intended victim. Montresor does not have to drink as much, but he has to act like a "drinking buddy" or else Fortunato is likely to become offended and suspicious. So Montresor's behavior, which includes showing Fortunato the trowel and claiming to be a fellow Mason, can be explained by the fact that he is a little bit drunk himself. The story would lose some verisimilitude if Fortunato were completely drunk and Montresor completely sober. Montresor, after all, owns large quantities of wine. He is obviously aa wine-lover, and would certainly drink some of his own wine on this perilous occasion. Furthermore, it would be understandable if Montresor wanted to consume some wine to keep up his courage and calm his nerves. He might also drink some wine to celebrate his achievement in getting Fortunato down off the streets and into his catacombs, where he has him at his mercy. Even if Montresor doesn't manage to get his victim to the place where he intends to chain him to the rock wall, he can murder him any time he wants. He specifies that he is armed with a rapier, while Fortunato must be unarmed because of his tight-fitting costume and because a sheathed sword would be totally inappropriate for the motley costume of a jester.