More generally than what you were told,
Let $f\colon X\rightarrow Y$ where $(X,\Sigma_X)$ and $(Y,\Sigma_Y)$ are measure spaces. $f$ is said to be measurable if for each $U\in\Sigma_Y$, $f^{-1}(U)\in\Sigma_X$.
A key point to note is that this is identical to definition of continuity (when replacing the measure spaces by topological spaces). We have simply required that the inverse map preserves measurability, while in topology, the inverse map of a continuous function preserves openness.
Now, let's specialize the definition to the case that you are concerned with. We use the symbol $\mathcal{B}$ to denote the Borel $\sigma$-algebra of $\mathbb{R}$.
Let $f\colon X\rightarrow\mathbb{R}$ where $(X,\Sigma_X)$ and $(\mathbb{R},\mathcal{B})$ are measure spaces. $f$ is said to be measurable if for each $B\in\mathcal{B}$, $f^{-1}(B)\in\Sigma_X$.
The theory of Lebesgue is concerned with being able to give a useful meaning to $\int f d\mu$. The reason we need $f$ to be measurable is because to define integration, we need to be able to approximate $f$ by simple functions.
As for examples of nonmeasurable functions, see this post. However, I recommend that first and foremost you read the approximation of the integral by integrals of simple functions linked to above, since it will give you an idea of why you are doing what you are doing.