Please let me know the purpose of the 'code sample' button in the menu while writing/editing questions/answers .
The "code sample button" is for, well, including code samples.
On different StackExchange sites, the typically included code are different. On sites like StackOverflow or TeX.SE, the questions and answers are generally about the code, and those code are marked in the presentation that way. On Math.SE, the most common use for including code samples is to show MatLAB or Mathematica code, either in the question or in the answers.
It is common practice to visually distinguish code samples from the surrounding text. This is especially important when you deal with programming languages such as Python where spaces and tabs are contextual. Without marking the code as such, typical browsers will chomp up the spaces, making the code unparseable.
So: use the code sample button if your question is actually about the code itself (or you are answering a question about certain code implementation). On Meta this certainly also applies to asking about TeX constructions for use with MathJax.